How can I alter "On Error" code so that different code is run depending on when the error is found?
Posted on 2012-04-12
I have a workd=sheet that includes a UserForm that loads when a button is clicked.
The user can enter a code in 10 individual fields.
If the code already exists within the column of another worksheet then I would like a message appear that says that the user cannot enter a duplicate code.
I have employed a NamedRange to accommodate this that is used elsewhere in the workbook for other functions.
I thought I could use the On Error code to allow passage through the code if there were no matches with NamedRange as below, but this of course doesn't work.
How can I ammend please?
On Error GoTo Stage3
If Me.TextBox101.Value = "" Then GoTo Stage3
zzz = 1
x2 = Application.WorksheetFunction.VLookup((Me.TextBox101.Value), Sheets("Tool Database").Range("Tools"), 3, 0)
On Error GoTo Stage4
If Me.TextBox106.Value = "" Then GoTo Stage4
zzz = 2
x3 = Application.WorksheetFunction.VLookup((Me.TextBox106.Value), Sheets("Tool Database").Range("Tools"), 3, 0)