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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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
 
Upvote 0
Thanks but i am getting an error
"Unable to get the Vlookup property of the worksheet function class"
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

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