Skrej
Board Regular
- Joined
- May 31, 2013
- Messages
- 176
- Office Version
- 365
- Platform
- Windows
I have the following code snippet which is supposed to check the values of some textboxes and dropdown boxes on a userform, in order to avoid duplicate entries.
While doing some testing, I couldn't figure out why it wasn't picking up duplicate entries. Then, I discovered that if that those values in the E column were alphanumeric, the code worked as expected, and gave the warning about a duplicate entry, and exited the sub as expected. However, if the values were strictly numeric, I don't get the message, and the rest of the sub continues to run and enters a duplicate entry.
Ultimately, I'll need those values (which are employee ID #'s) to be only numbers, so any suggestions on how to tweak my code? I can't change the format of the employee ID numbers.
Why aren't those IF statements recognizing duplicate numbers?
Edit: I realized it might help to show what I'd declared my variables as, so here they are.
Code:
'check for duplicates
rng = Sheet2.Cells(Rows.Count, "E").End(xlUp).Row
For Each MyCell In Sheet2.Range("E7:E" & rng)
If MyCell = Me.Reg3.Value And MyCell.Offset(0, 1).Value = Me.Reg4.Value And MyCell.Offset(0, 2).Value = Me.Reg5.Value Then
MsgBox "This training already exists for this staff member"
Exit Sub
End If
While doing some testing, I couldn't figure out why it wasn't picking up duplicate entries. Then, I discovered that if that those values in the E column were alphanumeric, the code worked as expected, and gave the warning about a duplicate entry, and exited the sub as expected. However, if the values were strictly numeric, I don't get the message, and the rest of the sub continues to run and enters a duplicate entry.
Ultimately, I'll need those values (which are employee ID #'s) to be only numbers, so any suggestions on how to tweak my code? I can't change the format of the employee ID numbers.
Why aren't those IF statements recognizing duplicate numbers?
Edit: I realized it might help to show what I'd declared my variables as, so here they are.
Code:
Dim cNum As Integer
Dim nextrow As Range
Dim MyCell As Range
Dim rng As Long
Last edited: