MFish
Board Regular
- Joined
- May 9, 2019
- Messages
- 76
I have a code to check for a duplicate in column B7 and downward. I need to somehow configure it so it finds a duplicate in row B7-downward AND C7-downward. Here's the kicker... I need it to be like an "AND" function. It will be OK if the unique ID's are duplicated in column B as long as the unique ID is not duplicated in column C.
[TABLE="width: 500, align: center"]
<tbody>[TR]
[TD]OAK
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]OAK
[/TD]
[TD]B
[/TD]
[/TR]
[TR]
[TD]OAK
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]THP
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]THP
[/TD]
[TD]B
[/TD]
[/TR]
[TR]
[TD]ONT
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]VIS
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]OAK
[/TD]
[TD]A
[/TD]
[/TR]
</tbody>[/TABLE]
Just imagine a userform that has a drop down list... One for the 3 letter acronyms and the other for A, B, C. Before it can make it onto the sheet... I want the userform, when trying to hit submit, to prompt you that you already have an OAK A on the list, please choose something else. Here's my code already...
Thanks.
[TABLE="width: 500, align: center"]
<tbody>[TR]
[TD]OAK
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]OAK
[/TD]
[TD]B
[/TD]
[/TR]
[TR]
[TD]OAK
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]THP
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]THP
[/TD]
[TD]B
[/TD]
[/TR]
[TR]
[TD]ONT
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]VIS
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]OAK
[/TD]
[TD]A
[/TD]
[/TR]
</tbody>[/TABLE]
Just imagine a userform that has a drop down list... One for the 3 letter acronyms and the other for A, B, C. Before it can make it onto the sheet... I want the userform, when trying to hit submit, to prompt you that you already have an OAK A on the list, please choose something else. Here's my code already...
Code:
Private Sub cmdSubmit_Click()
If cmbLH = "" Then
MsgBox "The Line Haul name cannot be blank. Please choose a valid Line Haul name for the run that you would like to add.", vbOKOnly, "Invalid Line Haul Name"
Exit Sub
Else: End If
If cmbOrig = "" Then
MsgBox "The Origination Depot cannot be blank. Please choose a valid Origination Depot selection for the run that you would like to add.", vbOKOnly, "Invalid Origination Depot Name"
Exit Sub
Else: End If
If cmbDest = "" Then
MsgBox "The Destination Depot cannot be blank. Please choose a valid Destination Depot selection for the run that you would like to add.", vbOKOnly, "Invalid Destination Depot Name"
Exit Sub
Else: End If
If txtDrivStart = "" Then
MsgBox "The Driver's start time cannot be blank. Please fill out before moving on.", vbOKOnly, "Invalid Driver Start Time"
Exit Sub
Else: End If
If txtLoad = "" Then
MsgBox "The Load Ready to Depart Time cannot be blank. Please fill out before moving on.", vbOKOnly, "Invalid Load Ready Time"
Exit Sub
Else: End If
If txtDep = "" Then
MsgBox "The Actual Departure Time cannot be blank. Please fill out before moving on.", vbOKOnly, "Invalid Actual Departure Time"
Exit Sub
Else: End If
If txtSeal = "" Then
MsgBox "The Seal No. cannot be blank. Please fill out before moving on.", vbOKOnly, "Invalid Seal No."
Exit Sub
Else: End If
If txtDate = "" Then
MsgBox "The Date cannot be blank. Please format the date as mm/dd/yyyy.", vbOKOnly, "Invalid Date"
Exit Sub
Else: End If
If txtName = "" Then
MsgBox "The Driver's name cannot be blank.", vbOKOnly, "Invalid Driver Name"
Exit Sub
Else: End If
If txtTruck = "" Then
MsgBox "The Truck Number cannot be blank. If TPC then type TPC", vbOKOnly, "Invalid Truck No."
Exit Sub
Else: End If
If txtTrailer = "" Then
MsgBox "The Trailer Number cannot be blank. If driving a bobtail then type N/A.", vbOKOnly, "Invalid Trailer No."
Exit Sub
Else: End If
If cmbTPCName = "" Then
MsgBox "The TPC selector cannot be blank. If it is not a TPC then choose N/A.", vbOKOnly, "Invalid TPC Selection"
Exit Sub
Else: End If
'''''' end of validation of blanks
''''''''''''''''''''''''
''''''''''''''''''''''''
'''''notify the user if the selection is not from the selection in the list provided
Range("B7").Select
'Check for duplicate bill name
Do Until UCase(ActiveCell) = UCase(cmbLH) Or ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
If ActiveCell <> "" Then
MsgBox "" & cmbLH & " 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
' Cannot override the duplicate line haul number
'forces the user to choose a different line haul number
''stop
''add in the sheet provided below
ActiveCell.Value = cmbLH
ActiveCell.Offset(0, 1).Value = cmbLeg
ActiveCell.Offset(0, 2).Value = txtDate
ActiveCell.Offset(0, 3).Value = cmbOrig
ActiveCell.Offset(0, 4).Value = cmbDest
ActiveCell.Offset(0, 8).Value = txtSeal
ActiveCell.Offset(0, 9).Value = txtName
ActiveCell.Offset(0, 11).Value = txtTruck
ActiveCell.Offset(0, 12).Value = txtTrailer
ActiveCell.Offset(0, 13).Value = cmbTPCName
ActiveCell.Offset(0, 14).Value = txtDrivStart
ActiveCell.Offset(0, 15).Value = txtLoad
ActiveCell.Offset(0, 17).Value = txtDep
If ob53.Value = True Then
ActiveCell.Offset(0, 10).Value = "53"
Else: End If
If ob28.Value = True Then
ActiveCell.Offset(0, 10).Value = "28"
Else: End If
If ob26.Value = True Then
ActiveCell.Offset(0, 10).Value = "26"
Else: End If
Unload Me
'''now sort table
sorttable
'''' move forward onto the selection of option buttons, 53, 28, 26
'''opens up the appropriate userform to fill out line haul load sheet
If ob53 = True Then
frmAdd.Hide
frm53.Show
End If
If ob28 = True Then
frmAdd.Hide
frm28.Show
End If
If ob26 = True Then
frmAdd.Hide
frm26.Show
End If
End Sub
Thanks.