WorksheetFunction.VLookup not working

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I get Run-time error '1004': Unable to get the VLookup property of the WorksheetFunction class on the VLookup line. Column H is formatted as date.

Code:
    Dim intRow As Integer
    Dim dteMax As Date

    intRow = Worksheets("Customer Product Export").Range("L" & Rows.Count).End(xlUp).Row
    dteMax = Application.WorksheetFunction.Max(Sheets("Customer Product Export").Range("H2:H" & intRow))
    UpdateMembershipPlan = Application.WorksheetFunction.VLookup(dteMax, Sheets("Current").Range("H2:L" & intRow), 5, False)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try:

Code:
UpdateMembershipPlan = Application.WorksheetFunction.VLookup(CDbl(dteMax), Sheets("Current").Range("H2:L" & intRow), 5, False)
 
Upvote 0
I'm afraid that didn't work. I changed the code to:

Code:
Public Function UpdateMembershipPlan() As String
    
    Dim intRow As Integer
    Dim dteMax As Long

    Sheets("Customer Product Export").Select
    intRow = Worksheets("Customer Product Export").Range("L" & Rows.Count).End(xlUp).Row
    Columns("H:H").Select
    Selection.NumberFormat = "0"
    dteMax = Application.WorksheetFunction.Max(Sheets("Customer Product Export").Range("H2:F" & intRow))
    UpdateMembershipPlan = Application.WorksheetFunction.VLookup(CDbl(dteMax), Sheets("Current").Range("H2:L" & intRow), 5, False)
'    UpdateMembershipPlan = "http://hsfsp/sites/hsfs/docs/Plans/Tailored/COOPERVISIONMP-APRIL2018v1.pdf"
    
End Function
 
Upvote 0
Then your lookup value is not being found.
 
Upvote 0
Silly me, I was using an incorrect sheet name. The CDbl function helped. Many thanks.
 
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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