Hide Superflous Subtotal Rows (Pivot Table 2010)

the_Intern

Board Regular
Joined
May 23, 2013
Messages
59
After spending hours on hours scouring the internet and this forum for the code that allows one to do this I came across a fabulous bit of code by BSALV dated from way back. I just finsihed my first major excel project and I have to say this was the best help I got. Handy for so many things as well as a great starting point to get you on the right track for non-referential manipulation. So here it is then
Code:
  Dim c As Range, c1 As Range, c2 As Range, b As Boolean, i As Integer, j As Integer, s As String
  With ActiveSheet.PivotTables("PivotTable3")
    i = .RowRange.Columns.Count
    On Error Resume Next
    Set c1 = .DataBodyRange.Columns(1)                     '1st column of databodyrange
    c1.EntireRow.Hidden = False
    Set c1 = Intersect(c1, c1.Offset(1))                   'without 1st cell
    If Not c1 Is Nothing Then
      For Each c In c1.Cells
        If IsError(c.PivotCell.RowItems(i).Value) Then     'this is a subtotal-row
          For Each c2 In Intersect(c.EntireRow, .DataBodyRange).Cells
            b = (c2.Value = c2.Offset(-1).Value)           'all cells equal to row above
            If Not b Then Exit For                         'stop as soon you discover 1 difference
          Next
          If b Then                                        'all cells are equal
            If IsError(c.Offset(-1).PivotCell.RowItems(i).Value) Then  'previous row is also a subtotal-row
              c.Offset(-1).EntireRow.Hidden = True         'hide previous row
            Else
              c.EntireRow.Hidden = True                    'hide this row
            End If
          End If
        End If
      Next
    End If
  End With
My hope is by reposting this it will be easier to find ;)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,225,644
Messages
6,186,151
Members
453,339
Latest member
Stu61

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