Programming around Vlookup Errors in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a program that uses vlookup to find values that are stored in a quote.
Some of the older quotes do no contain all of the fields “Lookup_Valuesâ€
that are in the newer quotes. When the program connot find a fileld
“Lookup_Value", excel stops my macro stops and highlightsts the vlookup
function that I am using. Is there a way to use if(iserror(vlookup))then...
or any other functions to work around this problem? I would like the vlookup
function to return "" to the active cell if the field "Lookup value" does not
exist.


Dim SerialRange As Range 'The range of the serial field, from the quote
Set SerialRange = Worksheets("Sheet1").Range("A:C")
Serial = (Application.WorksheetFunction.Vlookup("SER #:", SerialRange,
3, False))
ActiveCell.Formula = Serial
 
You have a couple of choices...

I like using application.vlookup() instead of
application.worksheetfunction.vlookup().

Dim Serial as Variant 'could be an error

serial = application.vlookup("ser #:", serialrange,3,false)

if iserror(searial) then
'no match code here
else
'found it code here
end if

====
or

on error resume next
serial = application.worksheetfunction.vlookup("ser #:", serialrange,3,false)
if err.number <> 0 then
'no match code here
else
'found it code here
end if
 
Thanks, It worked!

Dave Peterson said:
You have a couple of choices...

I like using application.vlookup() instead of
application.worksheetfunction.vlookup().

Dim Serial as Variant 'could be an error

serial = application.vlookup("ser #:", serialrange,3,false)

if iserror(searial) then
'no match code here
else
'found it code here
end if

====
or

on error resume next
serial = application.worksheetfunction.vlookup("ser #:", serialrange,3,false)
if err.number <> 0 then
'no match code here
else
'found it code here
end if
 

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

Similar Threads

Vlookup result in a message box 10
Vlookup Error 0
using vlookup in vba 10
Vlookup Error 3
Vlookup in VBA 2
Another Vlookup for VBA question 4
setting ranges and vlookup in custom functions 3
VBA using VLookUp 1

Back
Top