XLookup Structured Reference VBA

TheGREATrandino

New Member
Joined
Sep 9, 2020
Messages
15
Office Version
  1. 365
Platform
  1. Windows
I'm trying to use xlookup in a vba macro to search a table and I can't make it work.

in the spreadsheet this formula works =XLOOKUP(E3,tbl_DateRanges[Date Range],tbl_DateRanges[To])
In VBA Private Sub Worksheet_Change(ByVal Target As Range) this does not work
Range("I3").Value = Application.WorksheetFunction.XLookup(E3, Range("tbl_DateRanges[Date Range]"), Range("tbl_DateRanges[To]")
It generates Run-Time error "1004': Method "Range" of object _Worksheet' failed

when I try
Range("I3").Value = Application.WorksheetFunction.XLookup(E3,tbl_DateRanges[Date Range], tbl_DateRanges[To])
I get Compile error: Expected; list separator or )
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
The E3 needs to be specified as a range
VBA Code:
Range("I3").Value = Application.WorksheetFunction.XLookup(Range("E3"), Range("tbl_DateRanges[Date Range]"), Range("tbl_DateRanges[To]"))
 
Upvote 0
Range("I3").Value = Application.WorksheetFunction.XLookup(Range("E3"), Range("tbl_DateRanges[Date Range]"), Range("tbl_DateRanges[To]"))
didn't work.
Method "Range" of object "_Worksheet" failed
Also tried
VBA Code:
 Range("I3").Value = Application.WorksheetFunction.XLookup(Range("E3").Value, Range("tbl_DateRanges[Date Range]"), Range("tbl_DateRanges[To]"))
 
Last edited by a moderator:
Upvote 0
Got it to work
VBA Code:
Range("I3").Value = Application.WorksheetFunction.XLookup(Range("E3"), Tables.Range("tbl_DateRanges[Date Range]"), Tables.Range("tbl_DateRanges[To]"))
had to specify the name of the sheet because the proc that called xlookup was not on the same sheet as the tables
 
Last edited by a moderator:
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,331
Members
449,098
Latest member
thnirmitha

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