Sum variable blocks of cells

CookieMonster76

Board Regular
Joined
Apr 30, 2015
Messages
195
Hi

I have the following

A1 100
A2 100
A3
A4 100
A5 100
A6 100
A7
A8 100
A9 100
A10

I cells A3, A7 and A10 (currently empty) I want to sum the preceding cells. However, they are variable in length each time (i.e. Next time it may be that A4 will be summing A1 to A3).

In short I need the blank cells to sum those directly preceding them (but I don't want A7 to sum A1 to A6 once A3 has been populated, just A4 to A7).

I hope this makes sense and thanks for any help.

Paul
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Is col A hard values, or formulae?
 
Upvote 0
Hi

They are hard values - But will change each time what i am trying to do is created (i.e. they are hard coded but will be a different value.
 
Upvote 0
In that case how about
VBA Code:
Sub CookieMonster()
   Dim Rng As Range
   
   For Each Rng In Range("A:A").SpecialCells(xlConstants).Areas
      Rng.Offset(Rng.Count)(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
 
Upvote 0
In that case how about
VBA Code:
Sub CookieMonster()
   Dim Rng As Range
  
   For Each Rng In Range("A:A").SpecialCells(xlConstants).Areas
      Rng.Offset(Rng.Count)(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
Legend in your own lifetime

Thank you
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,820
Members
449,049
Latest member
cybersurfer5000

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