VBA: IfError and VLookup

FunsizedNerd

New Member
Joined
Mar 20, 2019
Messages
17
Trying to look up a value within a range using vlookup. If the value doesn't exist, then I want it to return either 0, nothing etc
Then I can use an if statement on the variable, so that if it IS nothing then I can do something (add the missing value to the end of a range)

Code:
test = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(cl.Value, checkvalues, 1, 0), 0)

It works fine if the value can be found within the range, but the second I come across one that isn't there, I get
Run-time error '1004': Unable to get the Vlookup property of the WorksheetFunction class

I know you can't use VLookup, that's why I have the IfError :mad:
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about
Code:
Dim Test As Variant
Test = Application.vlookup(cl.Value, checkValues, 1, 0)
If IsError(Test) Then
   'do somthing
End If
 
Upvote 0
Are you sure that you have used the code I suggested?
Because that wont give an "Unable to get the Vlookup property of the WorksheetFunction class" error.
Make sure that you do are not using "WorksheetFunction"
 
Upvote 0
If you use Application.Vlookup then the variable test will contain an error number which can be tested for.
If you use the WorksheetFunction then it crashes if it cannot find a match
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top