VBA Vlookup help!

Billy C

Board Regular
Joined
Aug 26, 2005
Messages
52
I have a user form that obtains details of a vehicle hire, in particular the date of hire, i then post this date back to a cell in a worksheet and then perform a vlookup to populate the next cell looking up the date from a table located in a different sheet within the same workbookin the code i have used is :- CurrDate = ActiveCell.Offset(0, 18).Value
ActiveCell.Offset(0, 13).Value = Application.WorksheetFunction.VLookup(CurrDate, RefTables!("B:C"), 2, False)
RefTables is the name of the sheet. When i run the code I get the error "Function not defined" can anyone please explain
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Fausto

New Member
Joined
Jul 28, 2004
Messages
44
Hello Billy C

Try editing the macro as follows:

Code:
ActiveCell.Offset(0, 13).Value = Application.WorksheetFunction.VLookup(CurrDate, Sheets("RefTables").range("B:C"), 2, False)

I hope this helps
 

Billy C

Board Regular
Joined
Aug 26, 2005
Messages
52
Thanks but i am getting an error
"Unable to get the Vlookup property of the worksheet function class"
 

Fausto

New Member
Joined
Jul 28, 2004
Messages
44
Hello

Wierd, but this error only occurs when working with dates. Please try the following and see if it serves your purpose:

Code:
Dim currdate As Long
currdate = DateValue(ActiveCell.Offset(0, 18).Value)
ActiveCell.Offset(0, 13) = Application.WorksheetFunction.VLookup(currdate, Sheets("RefTables").Range("B:C"), 2, False)

I managed to replicate your error message when I was using the dates. Once I changed the variable declaration on the currdate variable (plus using the datevalue function), it works. Obviously the date is read in as a number and then looked up. Dont know why VBA vlookup doesnt like dates (maybe some of the PRO's can answer), however it looks like my solution is a decent work around.

Hope this helps
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,052
Messages
5,835,146
Members
430,342
Latest member
Sailingexcel

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
Top