What is the Best way to "lookup" via VBA

BIGTONE559

Active Member
Joined
Apr 20, 2011
Messages
336
I originally posted about using vlookup to check in vba. I didn't receive any responses so i figured i was going about it the wrong way. Please share what you feel is the best way to resolve the following scenario:


You have 2 sheets of data.

on sheet 1 row 1:30 you have values in A1:D1
on sheet 2 row 1:30 you have values in A1:D1

you want to look up value D1 (Sheet1) with Value D1 (sheet2) and return B1 (Sheet2) value.

Then we would like to see if that result = to A1 (Sheet1)


I was using something like this:


Code:
If Application.WorksheetFunction.VLookup(Range(Cells(x, 4)), Range("checklist"), 2, False) = Cells(x, 2) Then

But i kept receiving range of object global fail.

What would anyone else suggest?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try like this

Code:
If Not IsError(Application.VLookup(Range(Cells(x, 4)), Range("checklist"), 2, False)) Then
    If Application.VLookup(Range(Cells(x, 4)), Range("checklist"), 2, False) = Cells(x, 2).Value Then
    'do something
    End If
Else
     'do something else
     
End If
 
Last edited:
Upvote 0
VOG thanks for the reply. .

There must be some error in dealing with the name ranges of workbook. Is there anyway that you can rewrite the code you provided for general ranges?

Everytime i attempted to execute the macro i receive "Range of object global fail"
 
Upvote 0
Perhaps you mean

Code:
If Not IsError(Application.VLookup(Cells(x, 4).Value, Range("checklist"), 2, False)) Then
    If Application.VLookup(Cells(x, 4).Value, Range("checklist"), 2, False) = Cells(x, 2).Value Then
    'do something
    End If
Else
     'do something else
     
End If
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

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