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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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)
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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