Need to calculate an average, in a vba generated subtotal

9tanstaafl9

Well-known Member
Joined
Mar 23, 2008
Messages
535
I have a macro that perfectly generates subtotals for me, but for one column only I need a subtotal that calculates an average for all cells that have values, ignoring the cells that have zero values. I created another column that made a count of zero or one if that column had a value in it or not, so I have another subtotal that gives me something to base the formula off of (I know what number to divide by), but I am too stupid to figure out how to know what cells to use for the range, since the number of cells will vary in each subtotal group.

Here is the code that creates the subtotal: note please explain in idiot terms any answers...

Code:
 Application.DisplayAlerts = False 
    Range(Range("a15:As15"), Range("a15:As15").End(xlDown)).EntireRow.Sort Key1:=Range("B15"), Order1:=xlAscending, Key2:=Range("C15" _
    ), Order2:=xlAscending, Key3:=Range("A15"), Order3:=xlAscending, Header _
    :=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
    xlSortNormal
    
    Application.EnableEvents = False
    Application.ScreenUpdating = False
        
    Range(Range("B15:At15"), Range("B15:At15").End(xlDown)).Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(14, 15, 16 _
    , 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 34, 35, 36, 38, 39, 40, 45), Replace:=True, PageBreaks:= _
    False, SummaryBelowData:=True  'note there is no 36 above since it's a percentage
    Application.EnableEvents = True

Thank you.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Ok, new question. Would there be any easy way to FIND this VBA generated subtotal for say column Q and replace it with a formula? I could let the first macro run and make a second macro that would do that after the fact?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

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