(Solved) – Checking userform entries for duplicates


please help. I am trying to create a user form in vba and I am checking the user inputs in the userform for duplicates in my database. I can get the userform to check for duplicates up to 4 criterions as shown below but once I include the check with the combobox MealPlan then it cannot see any duplicates anymore. Here is my code below:

Dim SprdSheet As Worksheet

Set SprdSheet = ThisWorkbook.Sheets("LNR Rates")

If Application.WorksheetFunction.CountIf(SprdSheet.Range("D:D"), Me.Inncode_B.Value) > 0 And _
    Application.WorksheetFunction.CountIf(SprdSheet.Range("F:F"), Me.CompanyName_B.Value) > 0 And _
    Application.WorksheetFunction.CountIf(SprdSheet.Range("G:G"), Me.DNumber_B.Value) > 0 And _
    Application.WorksheetFunction.CountIf(SprdSheet.Range("H:H"), Me.Rate_B.Value) > 0 And _
    Application.WorksheetFunction.CountIf(SprdSheet.Range("I:I"), Me.MealPlan_CB.Value) > 0 then 
    MsgBox "This is a duplicate"
    Exit Sub

End If

Leave a Reply

Your email address will not be published. Required fields are marked *