Trying to update code for to calculate range

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,079
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub TotalSum4() 'Add total sum to last row in column'
Dim r As Range: Set r = Cells(Rows.count, "M").End(xlUp)(2)
r = "Totals"
r(1, 2).Resize(, 1).FormulaR1C1 = "=SUM(R[-" & r.Row - 2 & "]C:R[-1]C)"
End Sub

This works for column M above, but i am trying to use this for a range below now for columns N to Z. I can not get it to work.

VBA Code:
Sub TotalSum5() 'Add total sum to last row in column'
Dim r As Range: Set r = Cells(Rows.count, [COLOR=rgb(184, 49, 47)]"N:Z")[/COLOR].End(xlUp)(2)  '<--- need help to get this to work'
r = "Totals"
r(1, 2).Resize(, 1).FormulaR1C1 = "=SUM(R[-" & r.Row - 2 & "]C:R[-1]C)"
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
try this code:
VBA Code:
Sub total5()
For i = 14 To 26
lastrow = Cells(Rows.Count, 13).End(xlUp).Row
collet = Chr(64 + i)

Cells(lastrow + 1, i).Formula = "=Sum(" & collet & "2:" & collet & lastrow & ")"
Next i
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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