I have the module below that searches for employees by their stamp number (i.e. W-2, W-21, W-25, etc.)
What it's doing incorrectly is when I search for "W-2", it brings up all the employees with a "2" in the stamp (e.g. I search for W-2, it brings ups W-2, W-21, W-22, W-23, etc.)
Is there a way to adjust this code so that it searches uniquely for the value that i enter?
Thanks,
Dandy
What it's doing incorrectly is when I search for "W-2", it brings up all the employees with a "2" in the stamp (e.g. I search for W-2, it brings ups W-2, W-21, W-22, W-23, etc.)
Is there a way to adjust this code so that it searches uniquely for the value that i enter?
Code:
'search by stamp function
Sub StampSearch()
Call InitVars
StampTab.Cells.ClearContents
StampTab.Cells.ClearFormats
Dim Found As Integer
'this looks to see if it is a numeric stamp or an alphabetic stamp (HYD, etc)
'it is also the main search function. It will return multiple values
'if the stamp appears more than once
Found = 0
i = 2
For x = 4 To LastRow
If IsNumeric(Stamp) Then
EmployeeStampNum = Stamp
If InStr(1, MatrixTab.Cells(x, 4), EmployeeStampNum) Then
NameLocation = x
StampTab.Cells(i, 1) = EmployeeStampNum
StampTab.Cells(i, 2) = MatrixTab.Cells(x, 1)
StampTab.Cells(i, 3) = MatrixTab.Cells(x, 2)
i = i + 1
Found = 1
Else
End If
Else
EmployeeStampString = Stamp
If InStr(1, MatrixTab.Cells(x, 5), EmployeeStampString) Then
NameLocation = x
StampTab.Cells(i, 1) = EmployeeStampString
StampTab.Cells(i, 2) = MatrixTab.Cells(x, 1)
StampTab.Cells(i, 3) = MatrixTab.Cells(x, 2)
i = i + 1
Found = 1
Else
End If
End If
Next x
'This is error proofing that allows the macro to avoid searching
'for an empty stamp number
If Stamp = "0" Or Stamp = "" Then
Found = 0
End If
If Found = 0 Then
MsgBox ("You did not enter a valid stamp number. Try using CAPITALS and removing all spaces.")
Else
StampTab.Cells(1, 1) = "Stamp #"
StampTab.Cells(1, 2) = "Employee Name"
StampTab.Cells(1, 3) = "Current Employee"
Thanks,
Dandy