Vllookup VBA Error

querylal

New Member
Joined
Nov 13, 2017
Messages
14
When i try below code it gives me error. "Unable to get the Vlookup property of the worksheetFunction class".

However when i copy paste vlookup formula used in VBA code in excell manually & change Cell(Z,2) value with B2 , then i gives right output. However when i keep Cell(2,2), it gives me error (N#A).

Sub ThreshXhigh()
Dim z As Integer
z = 2
While Cells(z, 2).Value <> ""


Cells(z, 19) = Application.WorksheetFunction.VLookup(Cells(z, 2), Master1, 19, False)


z = z + 1
Wend





End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try replacing cells(z,2) in the vlookup function with Range("B" & z).
 
Upvote 0
Kick out the worksheetfunction and refer to the sheet the range is placed.

Code:
Sub ThreshXhigh()
 Dim z As Integer
 z = 2
 While Cells(z, 2).Value <> ""
    
    Cells(z, 19) = Application.VLookup(Cells(z, 2), Sheet2.Range("Master1"), 19, False)

     z = z + 1
 Wend
 End Sub
 
Upvote 0
try
Dim z As Integer
z = 2
While Cells("B"&z).Value <> ""


Cells("S"&z) = Application.WorksheetFunction.VLookup(Cells("B"&z),Range(" Master1"), 19, False)


z = z + 1
Wend
 
Upvote 0
Upvote 0
@ querylal, what is Master1 in the formula?
 
Upvote 0
@ querylal, what is Master1 in the formula?


Master1 is table i am creating by calling procedure. And when i run code one by one it creates master table. It is just something to do with refering source cell column


Sub DefineTable1()
'
' DefineTable Macro
'


'
Sheets("ThreshServingLow.xlsx").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="Master1", RefersToR1C1:= _
"=ThreshServingLow.xlsx!R1C2:R5563C21"
End Sub
 
Upvote 0
That's a named range not a table and what is the name of the sheet that Cell(Z,2) is on?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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