Macro Multiple Data Sets in 1 sheet Varying Column Length Sum Function

xcelnovice

Board Regular
Joined
Dec 31, 2011
Messages
81
Hello,

I'd like to write a macro to sum Column D for each section of this sheet. Below is a sample but in my actual sheet the data continues on with various number of columns. I'm just learning macros have read how other threads but have trouble applying it to my sheet. So any notes explaining what the code is doing would be greatly appreciated.

BreadWhiteType 113.01%
Type 222.49%
Type 310.44%
Type 433.09%
Type 50.32%
Type 60.34%
Type 710.90%
Type 89.41%
BreadRyeType 139.98%
Type 258.84%
Type 30.57%
Type 40.61%
BreadWheatType 155.49%
Type 244.51%

<COLGROUP><COL style="WIDTH: 48pt" span=4 width=64><TBODY>
</TBODY>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
.
.

Assuming there's an empty row separating each group of percentages (as in your sample), then you could try something like this:

Code:
Sub SumAreas()

    Dim SRang As Range
    Dim SArea As Range
    
    On Error Resume Next
        With ActiveSheet.Columns("D")
            Set SRang = Union( _
                .SpecialCells(xlCellTypeConstants, xlNumbers), _
                .SpecialCells(xlCellTypeFormulas, xlNumbers))
        End With
    On Error GoTo 0
    
    If Not SRang Is Nothing Then
        For Each SArea In SRang.Areas
            With SArea.Offset(0, 1).Item(1)
                .Value = WorksheetFunction.Sum(SArea)
                .NumberFormat = "0.00%"
            End With
        Next SArea
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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