Combobox duplicate validation

MFish

Board Regular
Joined
May 9, 2019
Messages
76
Hi there,

I have two comboboxes that will NEED to go into two separate columns. I need the code to run if the two comboboxes have both been picked exactly the same on the sheet before moving forward... I tried writing this code and it doesn't work with concatenating.

Code:
Range("B7:C7").Select
        'Check for duplicate bill name
Do Until UCase(ActiveCell) = UCase(cmbLH) & UCase(cmbLeg) Or ActiveCell = ""
        ActiveCell.Offset(1, 0).Select
Loop

If ActiveCell <> "" Then
        MsgBox "" & cmbLH & cmbLeg & " already exists in the Table. Please choose a different Line Haul Number", _
    vbOKOnly, "Duplicate Line Haul Number detected"
    frmAdd.Show
Exit Sub

Else: End If

Any thoughts on how I can run a duplicate validation on two cells next to eachother and if those match what I just have in the two comboboxes?
 
Last edited by a moderator:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this


Code:
Private Sub CommandButton1_Click()
    'Validation
    Dim r As Range, f As Range, cell As String
    
    If cmbLH.ListIndex = -1 Or cmbLeg.ListIndex = -1 Then
        MsgBox "Select data"
        Exit Sub
    End If
    
    Set r = Range("B2", Range("B" & Rows.Count).End(xlUp))
    Set f = r.Find(cmbLH.Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        cell = f.Address
        Do
            If f.Offset(, 1).Value = cmbLeg.Value Then
                MsgBox "" & cmbLH & " " & cmbLeg & ", already exists in the Table. " & _
                    "Please choose a different Line Haul Number", _
                    vbOKOnly, "Duplicate Line Haul Number detected"
            End If
            Set f = r.FindNext(f)
        Loop While Not f Is Nothing And f.Address <> cell
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top