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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
That does not sum the columns correctly.

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

Thank You


79.246.262.713.4
81.355.5603.8
103.269.779.73.8
93.150.8873.1
96.369.385.810.7
59.434.439.617.8
78.640.170.4
183.5103164.5
130.874.8107.6
13283.4757.3
99.357.7
82.946.1
275.6
285.4
325.4

<colgroup><col width="72" span="4" style="width:54pt"> </colgroup><tbody>
</tbody>

The first code I posted gets the same result as doing it manually for me (H1:H4 in the below are manual formula, the yellow highlighted cells were with the code).


Excel 2010
ABCDEFGH
179.246.262.713.42106
281.355.5603.8000731
3103.269.779.73.81514.6
493.150.8873.152.6
596.369.385.810.7
659.434.439.617.8
778.640.170.452.6
8183.5103164.5
9130.874.8107.6
1013283.4757.3
1199.357.71514.6
1282.946.1
13275.6731
14285.4
15325.4
162106
Sheet2
Cell Formulas
RangeFormula
E2=SUM(E$1:E$1)
F2=SUM(F$1:F$1)
G2=SUM(G$1:G$1)
H1=SUM(A1:A15)
H2=SUM(B1:B12)
H3=SUM(C1:C10)
H4=SUM(D1:D6)
D7=SUM(D$1:D$6)
C11=SUM(C$1:C$10)
B13=SUM(B$1:B$12)
A16=SUM(A$1:A$15)


If you are getting different results I would expand your number of decimal places as I would suspect that your values aren't exact as displayed.
 
Last edited:
Upvote 0
Mark858

You are 100% correct the formula you sent works perfect. Thank You for you patience, not sure how I missed it.

One question - Does the "C refer to the column, any column with data?
 
Upvote 0
You are using R1C1 notation.

The R stands for Row, the C for Column.
C without a number means the same column as the cell the formula is in, if you had C[1] it would refer to the next column to the right and C[3] the column 3 to the right.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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