Vlookup Error Using Dates

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am getting an "Unable to get the Vlookup property of the WorksheetFunction class " error with the line in red below. This code opens the file (2021) Sunset.xlsx from the specified path and applies a vblookup function to compare the value tm (a true date) to the values in column 1 of the worksheet Sunset in the file opened by GetObject. Column 1 contains true date values. In testing for example, tm = 2021-06-20. There is a match at cell A112 (2020-06-20)

Rich (BB code):
With GetObject("D:/WSOP 2020/SupportData/(2021)Sunset.xlsx")
     Set Range1 = .Sheets("Sunset").Range("A:D")
     tm = ws_cdata.Cells(pebftp, 1).Value
     ssoff = Application.WorksheetFunction.VLookup(tm, Range1, 4, False)
     .Close
End With
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Does this work?
VBA Code:
Set Range1 = .Sheets("Sunset").Range("A:A")
tm = ws_cdata.Cells(pebftp, 1).Value
ssoff  = Range1.Find(tm).Offset(,3).value
.Close
 
Upvote 0
Solution
Thank you!! It appears to be working. Is this a reliable alternative to using vlookup? Any idea why the vlookup failed?
 
Upvote 0
Using a worksheet function in vba should be a last resort, there are many better ways of doing things with the built in functions of vba as they are designed to be used with it
Sorry that I don't know what is wrong with your VLookUp but this is the prefered method to replace it in vba
 
Upvote 0
That's good to know. I should have figured that there was more than one way to do things in Excel. I guess I need to understand the difference between worksheet functions and vba functions.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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