Working with R1C1 to insert a formula into a single cell

nicksoph

Board Regular
Joined
Jun 13, 2009
Messages
57
Im trying to write a formula into a cell, which will later be copied down its column but Im struggling with understanding how to write the formula in vba so it is suitable to be copied down.

The formula will be written to the right of a set of data which has a variable number of columns but always begins in column c and will total those columns which have TRUE in row 9.

If i were to write this in the excel gui fixed for two columns (C+D) the cell E8 would contain

=SUMPRODUCT($C$9:D$9*$C12:D12) which would copy down as expected

but in vba i want to be able to alter the column reference eg
If 'LC' holds the last column as a long and I wanted to write the formula on row 12 it would say the equivalent to

(12, LC + 1).Value = _

"=SUMPRODUCT($C$9:$(LAST_COLUMN)$9 * $C12:(LAST_COLUMN)12)"

How would I write this in VBA so the copying down would work?
Thanks
nic
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Something like
Code:
Range("G12").FormulaR1C1 = "=SUMPRODUCT(r9c3:r9c[-1]*rc3:rc[-1])"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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