Solved: trap error in VBA vlookup

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

spooky1

Thread Starter
Joined
Jan 29, 2010
Messages
126
My Target: find a company name in another sheet using wildcard vlookup and use the found name.

Below is what I have so far but if nothing is found macro craps out. If nothing found then need to go to add data to data base macro instead of coming up with an error. Any more elegant workable solutions?
My attempt works until another search is attempted by goto goo.


Sub a()
frt$ = "*"
pray$ = InputBox("enter in name", , "qwerqwerqw") & frt$ 'qwerqwerqw is for test purpose only

goo:

On Error Resume Next
xt1 = Application.VLookup(pray$, Sheets("company data").Range("$C$39:$C$49863"), 1, 0)
On Error GoTo enditall

MsgBox xt1 <comes up with error when it tries to display (#na)? result

Exit Sub

enditall:
If MsgBox("try again?", vbYesNo) = vbYes Then GoTo goo

End Sub
 
Joined
Sep 4, 2003
Messages
4,916
Just add an IF statement to determine if an error was received.

Code:
xt1 = Application.VLookup(pray$, Sheets("company data").Range("$C$39:$C$49863"), 1, 0)

If Not IsError(xt1) Then
'Your code to execute if match IS found
Else
'Your code to execute if match is NOT found
End If

Rollin
 

spooky1

Thread Starter
Joined
Jan 29, 2010
Messages
126
Methinks that all us newbies should band together and build you guys a temple on a hill somewhere!
Thanks once again!

If some religious deitites replied to prayers like you guys do to questions about excel, the world would not be in a similar mess to what my program would be without youse!
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top