VBA with XLOOKUP using different Tables

gberg

Board Regular
Joined
Jul 16, 2014
Messages
185
Office Version
  1. 365
Platform
  1. Windows
I am trying to come up with a VBA formula that pulls table names from different tables based on other criteria. I can get the table names but I am having issues making the name work with a XLOOKUP formula.

Here is a formula where I just use the table name itself

ActiveCell.FormulaR1C1 = _
"=XLOOKUP([@[PROJ '#]],Table71[PROJ '#],Table71[TOTAL JGP],""N/A"",0)"

Here is what I have tried

'Get Previous Month Table Name
Sheets(PM_tab).Select
Range("A2").Select
Dim TableName_PM_JPR As ListObject
Set TableName_PM_JPR = ActiveCell.ListObject
Sheets(JPR_tab).Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(RC[-24],TableName_PM_JPR[PROJ '#],TableName_PM_JPR[TOTAL JGP],""N/A"",0)"


The macro throws an error on the XLOOKUP formula. I know the table name "TableName_PM_JPR" is correct, I tested by pasting the value in a worksheet. Just not sure what I am doing wrong.

Thanks for any help
 
Peter, thank you so much! This has been much appreciated. You not only taught me a few things, how to put VBA into the forum and the best way to copy code, that has been very helpful and have also solved my issues with the VBA code itself! Good stuff!

Thanks,

Greg
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You're welcome. Glad we got there in the end. :)
 
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,803
Members
449,261
Latest member
Rachel812321

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