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...
Thank you.
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.