Index-Match using variables

Bill_Kro

New Member
Joined
Oct 28, 2017
Messages
14
I am trying to insert an Index-Match function into a table.
I get an error message when I try to use string variables in the formula.

The below works:

Dim T1 As String
Dim T2 As String
T1 = "Table1"
T2 = "Table2"

Sheets("Orig").ListObjects(T1).ListColumns("Revised").DataBodyRange = _
"=INDEX(Table2[CheckVal],MATCH(Table1[@Key],Table2[Key],0))"

I got the "=INDEX...." using the macro recorder.

However if I try to replace portions like "Table2" with the variable "T2" it doesn't work.

I wrote the following:
Sheets("Orig").ListObjects(T1).ListColumns("Revised").DataBodyRange = _
"=INDEX(""&T2&""[CheckVal],MATCH(Table1[@Key],Table2[Key],0))"

My ultimate goal is to replace all the parts of the Index-Match function with variables.

Please let me know if you need more information (1st time posting)
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the MrExcel board!

T2 already is a string so just concatenate it with the rest of the formula string. Try

Code:
Sheets("Orig").ListObjects(T1).ListColumns("Revised").DataBodyRange = _
"=INDEX(" & T2 & "[CheckVal],MATCH(Table1[@Key],Table2[Key],0))"
 
Last edited:
Upvote 0
Thank you Peter. That solved my problem. I just had the concatenate wrong. Thank you for the correction!
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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