R1CI Sum

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Good evening

A bit stumped on how to sum a range utilizing R1C1. My code is:

Thanks for any help.

Sub sumeverycolum()




Dim lastcolumn As Long
Dim lcol As Long
Dim lastrow As Long


lastcolumn = Cells.Find(what:="*", after:=Range("A1"), _
searchorder:=xlByColumns, searchdirection:=xlPrevious).Column


For lcol = 1 To lastcolumn

lastrow = Cells(Rows.Count, lcol).End(xlUp).Row

With Cells(lastrow + 1, lcol)

.FormulaR1C1 = "=Sum(R1C:R" & lastrow & "D)"



End With
Next

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Edit: actually the D isn't making much sense. What is the D supposed to do?
 
Last edited:
Upvote 0
The "D" is representing Column D. Should this be lcol?
Trying to work out what you are exactly trying to do if you are fixing it as column D when you are looping through all the columns?

Maybe you are just trying to sum the current column? if so it is just
Code:
.FormulaR1C1 = "=Sum(R1C:R" & lastrow & "C)"

or maybe multiple columns say 4 columns at a time then it would be
Code:
.FormulaR1C1 = "=Sum(R1C:R" & lastrow & "C[3])"

Obviously what shg has posted will give you the fixed column D if that is actually what you need.
 
Upvote 0
That does not sum the columns correctly.

Below is a sample of the data. The data starts in cells A1

Thank You


[TABLE="width: 288"]
<colgroup><col width="72" span="4" style="width:54pt"> </colgroup><tbody>[TR]
[TD="width: 72, align: right"]79.2[/TD]
[TD="width: 72, align: right"]46.2[/TD]
[TD="width: 72, align: right"]62.7[/TD]
[TD="width: 72, align: right"]13.4[/TD]
[/TR]
[TR]
[TD="align: right"]81.3[/TD]
[TD="align: right"]55.5[/TD]
[TD="align: right"]60[/TD]
[TD="align: right"]3.8[/TD]
[/TR]
[TR]
[TD="align: right"]103.2[/TD]
[TD="align: right"]69.7[/TD]
[TD="align: right"]79.7[/TD]
[TD="align: right"]3.8[/TD]
[/TR]
[TR]
[TD="align: right"]93.1[/TD]
[TD="align: right"]50.8[/TD]
[TD="align: right"]87[/TD]
[TD="align: right"]3.1[/TD]
[/TR]
[TR]
[TD="align: right"]96.3[/TD]
[TD="align: right"]69.3[/TD]
[TD="align: right"]85.8[/TD]
[TD="align: right"]10.7[/TD]
[/TR]
[TR]
[TD="align: right"]59.4[/TD]
[TD="align: right"]34.4[/TD]
[TD="align: right"]39.6[/TD]
[TD="class: xl63, align: right"]17.8[/TD]
[/TR]
[TR]
[TD="align: right"]78.6[/TD]
[TD="align: right"]40.1[/TD]
[TD="align: right"]70.4[/TD]
[TD="class: xl65"][/TD]
[/TR]
[TR]
[TD="align: right"]183.5[/TD]
[TD="align: right"]103[/TD]
[TD="align: right"]164.5[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="align: right"]130.8[/TD]
[TD="align: right"]74.8[/TD]
[TD="align: right"]107.6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]132[/TD]
[TD="align: right"]83.4[/TD]
[TD="class: xl63, align: right"]757.3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]99.3[/TD]
[TD="align: right"]57.7[/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]82.9[/TD]
[TD="align: right"]46.1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]275.6[/TD]
[TD="class: xl63"][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]285.4[/TD]
[TD="class: xl63"][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]325.4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

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