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
My hope is by reposting this it will be easier to find
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