worksheetFunction.vlookup doesnt work in my vba code

ke9c

Board Regular
Joined
Jul 27, 2010
Messages
75
hi, i am trying to do lookup in sheet "Rawdata", while referencing table sheet "CFG", but when i run till b=application.worksheetFunction.vlookup, it always prompt error msg "unable to get the vlookup property of the worksheetfunction class", can help? Thanks
-----------------------
Worksheets("RawData").Select
Call LoadTicker(Range("AA1", "AA100" ), -3)

Sub LoadTicker(rRange As Range, iOffset As Integer)
Worksheets("CFG").Select
Dim varCell As Range
For Each varCell In rRange.Cells
varCell.Select
Dim b As Variant
b = Application.WorksheetFunction.VLookup(varCell.Offset(0, iOffset ).Value, Range("A10", "B14"), 2, False)
varCell.value=b
' varCell.FormulaR1C1 = "=VLOOKUP(RC[-2],rr,2,FALSE)"

Next varCell
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
And even if i use b = Application.WorksheetFunction.VLookup("aa", Range("C17", "D30"), 2, False), i will get same error
 
Upvote 0
Please can you be explicit about where the lookup values are (please give actual sheet name and range address - not just range name) and where the lookup range resides (sheet name and range address). You currently appear to have problems caused by unqualified references (you are probably pointing at ranges you didn't intend).

Note that you will be able to do this without looping - so please answer my first questions above.
 
Upvote 0
Is "aa" a sheet name or a named range ??
It needs to be a single cell reference I believe, also
Have you tried using
Code:
b = Application.WorksheetFunction.VLookup("aa", Range("C17:D30"), 2, False)
 
Upvote 0
aa is a string, i want to test whether vlookup function can lookup out data in CFG sheet based on first column have value "aa". Thanks
 
Upvote 0
My Table is as below, basically, i want to use vlookup in RawData sheet, if CFG C col contains Y col Data, then overwrite AA col in RawData with value in D col of CFG sheet.

In RawData
Y Col AA Col
----- ------
aaa xxx
bbb yyy
ccc zzz

In CFG
C col D Col
----- ------
aaa ggg
ddd hhh
eee iii
 
Upvote 0
I'm not quite following you but if you are looking for a string "aa" then you will have to include an IF statement in your VLOOKUP, because it won't do the search for you.
I'd suggest you reread Richards post and provide us with more info.
 
Upvote 0
yes, i should use if, but \whenever i use vlookup in this way, the debugger will complain, so i cannot get a value out to do comparision in if statement.
 
Upvote 0
Hi

Try this:

Code:
Sub Test()
Dim vArray As Variant  'use this to hold all lookedup values (means we can do lookup in one go)
Dim i As Long  'for next counter
Dim rngOfValues As Range

With Sheets("Raw Data")
    Set rngOfValues = .Range("Y1:Y" & .Cells(.Rows.Count, "Y").End(xlUp).Row)
End With

vArray = Application.VLookup(rngOfValues.Value, Sheets("CFG").Range("C:D"), 2, 0)


For i = 1 To UBound(vArray, 1)
    If IsError(vArray(i, 1)) Then _
        vArray(i, 1) = rngOfValues.Cells(i, 1).Offset(, 2).Value 'this serves to replace any error values (ie those without a match on sheet CFG) with the existing value in Raw Data
Next i

'write values back to Raw Data sheet:

rngOfValues.Offset(, 2).Value = vArray


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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