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!!
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

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,453
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
 

Watch MrExcel Video

Forum statistics

Threads
1,113,953
Messages
5,545,145
Members
410,666
Latest member
Al3cs
Top