IsError & VLookup in VBA statement

jfarc

Active Member
Joined
Mar 30, 2007
Messages
316
I have this formula in Cell F2 and it works fine:
Code:
IF(ISERROR(VLOOKUP(A2,INV,1,0))=FALSE,"D","")

I am trying to replicate the above formula as a VBA command line and when it tries to execute the 'IsError...' line I am getting an Error #1004 - Unable to get the VLookup property of the WorksheetFunction class.

Code:
        iFound = WorksheetFunction.IsError(WorksheetFunction.VLookup(Range("A2"), Range("INV"), 1, 0))
        If iFound = False Then Range("F2").Value = "D"

What am I doing wrong?
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try

Code:
iFound = IsError(Application.VLookup(Range("A2").Value, Range("INV"), 1, 0))
 
Upvote 0
Ok, that worked!

But, I also had the following line of code that worked fine:
Code:
  CUST = WorksheetFunction.VLookup(Range("D7"), Range("CCODES"), 1, 0)

When do you determine to use the 'Application.' vs. the 'WorksheetFunction.' and when not to use them at all?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,245
Members
452,900
Latest member
LisaGo

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