VLOOKUP in VB code

  • Thread starter Thread starter Phillip Topping
  • Start date Start date
P

Phillip Topping

I am having trouble getting the VLOOPUP function to work in a macro. I can
get VLOOKUP to work perfectly in a cell formula but when I try and repeat
this in a macro I keep getting an error message.

If dlgFeesForm.txtEquipHirePeriod.Value < 5 Then

dailyvalue = dlgFeesForm.txtEquipHirePeriod.Value
'dailyrate =
Application.WorksheetFunction.VLookup(dailyvalue, DailyHireRates, 2, False)

End If

My error message appears whenever the macro reaches the line with Vlookup in
it, what am I doing wrong??

And yes I know its a comment at the moment, I have done this so I can test
the remainder of the macro.

TIA
Phillip
 
Phillips,

Is DailyHireRates a worksheet named range? If so, use
Range("DailyHireRates") in the formula.
 
What is "DailyHireRates"? It would have to be a Range variable for the
code to work. If, for example, it is a range name, then you need
Range("DailyHireRates") instead of DailyHireRates.

Alan Beban
 
Bob and Alan,
Yes it is a named range and I had tried doing what you both suggested but I
still get the same error message.

Here is the changed code:

If dlgFeesForm.txtEquipHirePeriod.Value < 5 Then

dailyvalue = dlgFeesForm.txtEquipHirePeriod.Value
dailyrate = Application.WorksheetFunction.VLookup(dailyvalue,
Range("DailyHireRates"), 2, False)

End If

Here is the error message I get in the dialogue box:

Run-time error '1004':

Unable to get the Vlookup property of the WorksheetFunction class

Phillip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VLOOKUP error in VBA 1
problem with Vlookup in macro 2
vlookup VBA code 14
vlookup problem 10
<<<<excel and VB lookup 2
VLookUp in VBA 2
Using activecell in vlookup 3
VLOOKUP as a vb code 5

Back
Top