Question related to dynamic file name

rkb1510

New Member
Joined
Oct 24, 2024
Messages
15
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have one code which is using formula, in below format
dstws.Range("A2").FormulaR1C1 = "=INDEX([obj_3_Table.csv]obj_3_Table!R2C6:R" & lastRowSrc & "C6, MATCH(RC[3],[obj_3_Table.csv]obj_3_Table!R2C1:R" & lastRowSrc & "C1, 0))"

but I want to generalize this formula depending on file name and sheet name something like below
dstws.Range("A2").FormulaR1C1 = "=INDEX(" & [srcwb.Name] & srcsheetanme & "!R2C6:R" & lastRowSrc & "C6, "MATCH(RC[3]," & [srcwb.Name] & srcsheetanme & "!R2C1:R" & lastRowSrc & "C1,0))"

but when i try this it is keep giving me error or not working. To debug i have try to print formula after it set, and found out formula is not taking correct names
 
Formula in below format is working just have to add missing square brackets before and after srcwb.Name in order match it with actual formula

formulastr = "=INDEX(" & srcwb.Name & srcsheetanme & "!R2C6:R" & lastRowSrc & "C6, " & _
"MATCH(RC[3]," & srcwb.Name & srcsheetanme & "!R2C1:R" & lastRowSrc & "C1,0))"
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,253
Members
453,784
Latest member
Chandni

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