Using variable cell reference in vba to insert formula

trodneyrotter

New Member
Joined
Jun 20, 2014
Messages
15
Hi,

I think I'm nearly there with this, but just need a bit of help tweaking it to make it work. I'm wanting to use vba to add an indirect formula in a range of cells with a lastrow variable.

So far I have this, but I can't get the last row variable to work. When I set the Range as (D20:F30) it works great, but when I add in the last row variable it errors on the (""'""&RC3&""'!""&R19C), stating Expected: list separator or ).

Code:
Sub AddIndirect()
Dim thisRow As Long
thisRow = Range("A" & Rows.Count).End(xlUp).Row
'ActiveCell.Offset(0, 1).Formula = "=SUM(C" & thisRow & "!" & "$D19)"
Range("D20:F " & lastrow").FormulaR1C1 = "=SUM(INDIRECT(""'""&RC3&""'!""&R19C))"
End Sub


[code/]

I'm really trying to get to grips with the ampersand syntax, but its just not sinking in.

Thanks for your help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Looks like the problems were with your variable names and space after the :F

Rich (BB code):
Sub AddIndirect()
Dim lastRow As Long
lastRow = Range("A" & Rows.Count).End(xlUp).Row
'ActiveCell.Offset(0, 1).Formula = "=SUM(C" & thisRow & "!" & "$D19)"
Range("D20:F" & lastRow).FormulaR1C1 = "=SUM(INDIRECT(""'""&RC3&""'!""&R19C))"
End Sub
 
Upvote 0
Oh wow, thank you so much! I've obviously been staring at this too long and didn't even see that.

Thanks again, I really appreciate your help. Time for me to get some zzzz I think :)
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,589
Members
449,237
Latest member
Chase S

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