Sum above to blank cell - dynamic range

jasonfish11

Board Regular
Joined
May 14, 2015
Messages
56
Hi,
I'm building a macro and trying to add sums in the total sections. I would like to sum everything above the formula until it reaches the 2nd blank cell (stopping at the header).

I'm struggling a bit with the logic.

Example I want to sum O9-O13 (notice O13 is a blank cell, hence the desire to go to 2nd blank) and put that total in O14. I also want to sum O17:O19 and have that value in O20, etc etc until I have no more data sub-sections.

The rows data in these subsections will be dynamic based on the reports I'm getting.

Any help with the logic would be greatly appreciated.

Thank you in advance,
Jason
 

Attachments

  • picture.png
    picture.png
    29.8 KB · Views: 8
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Sorry I made a very quick change meaning I don't have to go to the 2nd blank, just the 1st blank (or header). But didn't know how to delete & repost my original post.
 

Attachments

  • pic2.png
    pic2.png
    17.1 KB · Views: 8
Upvote 0
Is the header row always row 8 & are the cells with Total in col N?
 
Upvote 0
Is the header row always row 8 & are the cells with Total in col N?
Yes header will always be row 8.

The word "Total" is in column N, but the actual sum of the sub sections will be in column O and P. The columns are not dynamic, nor is the header. But everything below would be.
 
Upvote 0
Thanks for that, I forgot to ask are the values in col O hard values or formulae?
 
Upvote 0
In that case will the formula also be in the "blank" cells?
 
Upvote 0
Ok, how about
VBA Code:
Sub jasonfish()
   Dim Rng As Range
   
   For Each Rng In Range("O9:O" & Range("N" & Rows.Count).End(xlUp).Row).SpecialCells(xlFormulas).Areas
      Rng.Offset(Rng.Count).Resize(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub jasonfish()
   Dim Rng As Range
  
   For Each Rng In Range("O9:O" & Range("N" & Rows.Count).End(xlUp).Row).SpecialCells(xlFormulas).Areas
      Rng.Offset(Rng.Count).Resize(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
Wow that works perfectly.

Thank you so much for your help.
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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