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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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


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>
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,405
Members
448,958
Latest member
Hat4Life

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