Hi
I'm having a go at handling errors for the first time and having trouble. What I am doing is looking up a staff number (entered on a userform) on a spreadsheet. If the staff number doesn't exist then this works fine, however if the staff number does exist it still picks up an error even though there isn't one. Any clues?
Set FlexSource = Worksheets("Data").Range("A8:IV60000")
On Error GoTo ErrorHandler
NumberCheck = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 1, False)
On Error GoTo 0
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 1004 ' the correct error?
MsgBox "That staff number does not exist on the Flex database"
Exit Sub
Case Else
MsgBox "some other error"
End Select
Resume
I'm having a go at handling errors for the first time and having trouble. What I am doing is looking up a staff number (entered on a userform) on a spreadsheet. If the staff number doesn't exist then this works fine, however if the staff number does exist it still picks up an error even though there isn't one. Any clues?
Set FlexSource = Worksheets("Data").Range("A8:IV60000")
On Error GoTo ErrorHandler
NumberCheck = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 1, False)
On Error GoTo 0
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 1004 ' the correct error?
MsgBox "That staff number does not exist on the Flex database"
Exit Sub
Case Else
MsgBox "some other error"
End Select
Resume