PDA

View Full Version : [SOLVED:] Pivot Table Subtotals



Opv
09-11-2013, 07:53 AM
Are subtotals within Pivot Tables applicable only at the field level, i.e., is the only option to either turn them on or off for all items within a field (all or nothing)? Or, is it possible to selectively apply subtotals to specific grouped pivot items? There are, for example, only three or four sets of grouped items within my table to which I am interested in having the subtotals displayed. I've tried looping through and hiding the subtotals for the other individual items but can't seem to get rid of them.

Opv
09-11-2013, 11:04 AM
Oddly enough, I finally came up with the following and it seems to work.


Sub SubtotalOnlyGroupItems()
Sheets("PIVOT").Cells.EntireRow.Hidden = False
Dim cel As Range, rng As Range, fRng As Range, LastPTRow As Long
Dim MyGroups As String
MyGroups = "AUTO, HOUSEHOLD, MEDICAL, UTILITIES, Grand Total"
Set rng = Sheets("PIVOT").Range("A:A")
LastPTRow = WF.Index(rng, WF.Match(WF.Rept("z", 255), rng)).Row
Set fRng = Sheets("PIVOT").Range("A4:A" & LastPTRow)
For Each cel In fRng
If InStr(1, cel.Value, "Total") > 0 And _
InStr(1, MyGroups, Left(cel.Value, 4)) = 0 Then
cel.EntireRow.Hidden = True
End If
Next cel
End Sub