VLOOKUP Macro

wherbjr35

New Member
Joined
Nov 2, 2004
Messages
19
Can someone please advise me on the syntax needed to translate a VLOOKUP statement from a formula to some IF or ISNA statements. My goal is to us VLOOKUP to compare data from 2 worksheets for congruency. Essentially, this formula can be applied to one cell.

VLOOKUP(CheckCell, CheckRange, 1, False).

I am trying to achieve this:

If(VLOOKUP(CheckCell, CheckRange,1,False)) = "true" Then
MsgBox ("No errors")
Else
If(VLOOKUP(CheckCell, CheckRange,1,Flase)) = "false" then
MsgBox ("You have errors")
EndIf
End Sub

I am confused on how the formula would translate into VBA code. Thanks for any advice. I love this site!!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

mtb'r

New Member
Joined
Sep 8, 2006
Messages
42
In VBA, you can activate the VLOOKUP function by entering "application.worksheetfunction." in front of it...

e.g.:
Range("A1") = application.worksheetfunction.vlookup(checkcell, checkrange,1,false)
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
Hello wherbjr35,
I'm not sure I understand your intent with the code.
Are you just trying to confirm the existance of the CheckCell's value within the CheckRange?

If so it could be done using the CountIf (>0) sheet function in your code easier than vlookup.

Example (Using named ranges...):
Code:
If Application.WorksheetFunction. _
  CountIf(Range("CheckRange"), Range("CheckCell")) > 0 Then
    MsgBox ("No errors")
Else
  MsgBox ("You have errors")
End If
 

Forum statistics

Threads
1,143,638
Messages
5,719,979
Members
422,254
Latest member
sayedsaid

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
Top