I have a Userform that asks the user to enter a UK post code into 2 text fields. e.g
txtField1 = L27
txtField2 = 4HD
I then have a Lookup function using txtField1 to search for the first part of the postcode in a list to return a result. Everything works swimmingly until an incorrect post code is entered.
I then get a run-time error which is not ideal for the user.
Is there a way I could write some error handling code that tells the user an invalid post code has been entered rather than getting the run-time error?
My Lookup function is here:
ws.Cells(lRow, "D") = WorksheetFunction.VLookup(txtPost1, Sheets("Postcodes").Range("A1:E5000"), 5, False)
ws.Cells(lRow, "E") = WorksheetFunction.VLookup(txtPost1, Sheets("Postcodes").Range("A1:E5000"), 3, False)
This is the current error handling I have in place but this obviously doesn't pick up if an invalid post code has been entered.
If txtPost1.Value = "" Or Nullstring Then
MsgBox "Please enter a valid Postcode area (i.e B90)", vbCritical, "Error"
Me.txtPost1.SetFocus
GoTo error1
End If
If there is any standard error handling code to effectively by-pass the run-time error then this should work fine.
Thanks in advance.
Bookmarks