on error goto

G

Guest

Hi all!

i have the following code:

<BEGIN VBA CODE>
On Error GoTo errorhandler1
Set loc1 =
wamer.Offset(Application.WorksheetFunction.Match(addCodeBox, Range(wamer,
find), 1), 0)

errorhandler1:
Set loc1 =
wamer.Offset(Application.WorksheetFunction.Match(addCodeBox, Range(wamer,
find), -1) - 1, 0)
Resume Next
<END VBA CODE>

if i am thinking correctly, this should execute the first set loc1 and if an
error is found, then go to errorhandler1 and execute that code, then continue
with the next line after resume next - correct?

and if no error found, then it should skip errorhandler1 altogether?

if this is true - why is it not skipping the errorhandler1?
(i have tried commenting out the
on error goto, errorhandler1, the second set loc1, and resume next
and no error is found.

am i not going about this correctly?
 
T

Tom Ogilvy

If the first is successful, the code then executes the code in the
errorhandler just as you reserved. The label errorhandler1 is nothing but
that, a label. It just marks a position in the code. You could have named
it
Gixxer_J_97:

and use
on Error goto Gixxer_J_97



It would be something like:

<BEGIN VBA CODE>
On Error GoTo errorhandler1
Set loc1 = wamer.Offset(Application. _
WorksheetFunction.Match(addCodeBox, _
Range(wamer, find), 1), 0)
goto NextTest
errorhandler1:
Set loc1 =
wamer.Offset(Application. _
WorksheetFunction.Match( _
addCodeBox, Range(wamer, _
find), -1) - 1, 0)
Resume NextTest
NextTest:
<END VBA CODE>
 
G

Guest

thanks Tom -
i think i was thinking that it was more of a control structure like if / endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top