Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Help with vlookup in vba, how to deal with errors?

  Asked By: Lloyd    Date: Nov 28    Category: MS Office    Views: 686
  

If the vlookup fails i want to do something else, how do i know if it fail?? how
do i write my code??

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Adalia Fischer     Answered On: Nov 28

Your statement is rather vague. Do you mean the code  just flat out fails
to run, or do you mean your vlookup  statement doesn't find what you are
looking for?

I would imagine you are referring to your statement as to not finding
anything, in which case, something as simple as a Boolean statement
could work.

Boolean statements are true\false variables.

Dim bFoundIt as Boolean

At some point within your code you could change the variable to true,
i.e.
bFoundIt = True
if what you are looking for is found, otherwise it will remain as false.

Then run an if statement afterwards, such as

If bFoundIt = false then
Do something
End if

 
Didn't find what you were looking for? Find more on Help with vlookup in vba, how to deal with errors? Or get search suggestion and latest updates.




Tagged: