Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ryan Anderson   on Jan 15 In MS Office Category.

  
Question Answered By: Vonda Ramirez   on Jan 15

In vba  something along these lines?:

Sub sequently()
On error  GoTo gonewrong
Debug.Print Application.WorksheetFunction. _
VLookup(Range("G10"), Range("D10:E17"), 2, False)
On Error GoTo 0
Exit Sub
gonewrong:
MsgBox "yuk!"
End Sub

The On Error statement applied just before the vlookup  statement, then
cancelled straight after that statement with On Error GoTo 0 (Actually
unnecessary above as the vlookup statement is the only one and On
Error statements  are cancelled on exit from the procedure they were
used in!).
In this case the On Error statement, when met by any error, will
divert to the code after the label 'gonewrong'.
To prevent that portion of code being executed inappropriately (when
there is no error), the Exit Sub line is inserted just before it.

ps Debug.Print prints to the immediate window in the VBE; Ctrl+G in
the VBE if you can't see it.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Vlookup in vba when lookup fails Or get search suggestion and latest updates.


Tagged: