VBA to sum based on certain criteria

markh1182

New Member
Joined
Apr 25, 2006
Messages
48
Hi, more help required I'm afraid.

In cells A1 to A4 I might have values of 100.00. In cell A6 might be 200.00 and cells A9 to A12 I might have 300.00.

What I want is in cell B5 it will put an X so that in cell C5 it can sum the amounts A1 to A4. In cell B7 it will put an X and sum in C7 and B13 will be an X and C13 will be a sum of A9 to A12.

Now I am sure this is possible but not sure how to about it. In effect every gap it will sum the previous x rows.

Thank you, Mark
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615
Hi,

Try,

Code:
Sub SumBlocks()
Dim SumRng  As Variant
Dim aRng    As Range

For Each aRng In Columns(1).SpecialCells(xlCellTypeConstants, 1).Areas
    SumRng = aRng.Address(0, 0)
    Cells(aRng.Row + aRng.Rows.Count, "A") = "=SUM(" & SumRng & ")"
Next
End Sub

HTH
 

Forum statistics

Threads
1,136,991
Messages
5,678,993
Members
419,797
Latest member
ikethegenius

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
Top