Add every range of cells say 31 cells

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I am looking for a script that will add from say G3 to G33 then place the result in G34. From there, add from G35 to G65 then place result in G66. And continue till the last used row. Here let us track the last used row from column A.

Thanks in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi,
I am looking for a script that will add from say G3 to G33 then place the result in G34. From there, add from G35 to G65 then place result in G66. And continue till the last used row. Here let us track the last used row from column A.
Does this do what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub Sum31Cells()
  Dim R As Long, LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  For R = 34 To LastRow Step 32
    Cells(R, "G").Value = Application.Sum(Cells(R, "G").Offset(-31).Resize(31))
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Code:
Sub Add_30()
    Dim i As Long, lr As Long, j As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    j = 34
    For i = 3 To lr Step 31
        Range("G" & j).FormulaR1C1 = "=SUM(R[-31]C:R[-1]C)"
        j = j + 32
    Next i
End Sub
 
Upvote 0
Does this do what you want...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub Sum31Cells()
  Dim R As Long, LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  For R = 34 To LastRow Step 32
    Cells(R, "G").Value = Application.Sum(Cells(R, "G").Offset(-31).Resize(31))
  Next
End Sub[/TD]
[/TR]
</tbody>[/TABLE]

Exactly! !!

Very cool.

Thanks a lot
 
Upvote 0
Code:
Sub Add_30()
    Dim i As Long, lr As Long, j As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    j = 34
    For i = 3 To lr Step 31
        Range("G" & j).FormulaR1C1 = "=SUM(R[-31]C:R[-1]C)"
        j = j + 32
    Next i
End Sub


Oh okay I recorded this macro I forgot how to fix that loop.

Thanks for the fix!!!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
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