FormulaR1C1 + reference problem

athielem

New Member
Joined
Apr 22, 2020
Messages
9
Hi guys! :)

So, I've got this piece of code, which is working:

VBA Code:
ws.Range("A$" & rowCount & ":" & "AX1").FormulaR1C1 = "=[lol.xlsx]korr!RC"

It simply copies A1 from one file to A1 of the other file, but with explicitly referencing the path (which is exactly what I need). However, as I have to do this step for many files, I would like to somehow substitute the exact path of the file and the sheet name lol.xlsx]korr with a variable.

I have been sitting on this problem for the entire day now, trying out unsuccessfully all sorts of different possibilities.

I would be very grateful if someone could help me out with some advice!

Regards,
Andreas
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Andreas

How are you defining and setting the value you want to use to replace the hard-coded value in the formula?
 
Upvote 0
Maybe
VBA Code:
Dim s As String
s = "[lol.xlsx]korr"
ws.Range("A$" & RowCount & ":AX1").FormulaR1C1 = "='" & s & "'!RC"
 
Last edited:
Upvote 0
I am now trying to adapt the range so that it always starts selecting from A2; the first row is composed of column titles, which should actually not be copied.

I have tried it unsuccessfully with this code:

VBA Code:
ws.Range("A$" & 2 & ":" & "A$" & rowCount & ":" & "AX1").FormulaR1C1 = "='" & y & "'!RC"

What mistake am I making here? :confused: Can I adapt the range that way? Or do I need a different approach altogether?

Thank you for any suggestion!
 
Upvote 0
Hi, you can try like this:

ws.Range("A$2:AX" & RowCount).FormulaR1C1 = "='" & s & "'!RC"
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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