Skip to content

Instantly share code, notes, and snippets.

@palikhov
Created August 7, 2019 13:37
Show Gist options
  • Save palikhov/b0a1c7d75615c643240d181fbc5db554 to your computer and use it in GitHub Desktop.
Save palikhov/b0a1c7d75615c643240d181fbc5db554 to your computer and use it in GitHub Desktop.
Another vb code to hide rows between pivot tables
Sub HideRowsBtwnPivots()
'--Hides all rows between two PivotTables.
Dim lPivot1LastRow As Long, lPivot2FirstRow As Long
'---Get last row of top PivotTable
With ActiveSheet.PivotTables("PivotTable1").TableRange2
lPivot1LastRow = .Row + .Rows.Count - 1
End With
'---Get first row of bottom PivotTable
With ActiveSheet.PivotTables("PivotTable2").TableRange2
lPivot2FirstRow = .Row
End With
'--Hide rows in-between
If lPivot1LastRow + 1 < lPivot2FirstRow Then _
Rows(lPivot1LastRow + 1 & ":" & lPivot2FirstRow - 1).Hidden = True
End Sub
Sub HideAllButXRowsBtwnPivots()
'--Hides blank rows between two PivotTables.
Dim lPivot1LastRow As Long, lPivot2FirstRow As Long
Const lRowsBtwn As Long = 12
'---Get last row of top PivotTable
With ActiveSheet.PivotTables("PivotTable1").TableRange2
lPivot1LastRow = .Row + .Rows.Count - 1
End With
'---Get first row of bottom PivotTable
With ActiveSheet.PivotTables("PivotTable2").TableRange2
lPivot2FirstRow = .Row
End With
'--UnHide rows in-between
If lPivot1LastRow + 1 < lPivot2FirstRow Then _
Rows(lPivot1LastRow + 1 & ":" & lPivot2FirstRow - 1).Hidden = False
'--Hide all but specified number of rows in-between
If lPivot1LastRow + 1 + lRowsBtwn < lPivot2FirstRow Then
Rows(lPivot1LastRow + 1 + lRowsBtwn & _
":" & lPivot2FirstRow - 1).Hidden = True
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment