Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. Sub HideRowsBtwnPivots()
  2. '--Hides all rows between two PivotTables.
  3.  
  4. Dim lPivot1LastRow As Long, lPivot2FirstRow As Long
  5.  
  6. '---Get last row of top PivotTable
  7. With ActiveSheet.PivotTables("PivotTable1").TableRange2
  8. lPivot1LastRow = .Row + .Rows.Count - 1
  9. End With
  10.  
  11. '---Get first row of bottom PivotTable
  12. With ActiveSheet.PivotTables("PivotTable2").TableRange2
  13. lPivot2FirstRow = .Row
  14. End With
  15.  
  16. '--Hide rows in-between
  17. If lPivot1LastRow + 1 < lPivot2FirstRow Then _
  18. Rows(lPivot1LastRow + 1 & ":" & lPivot2FirstRow - 1).Hidden = True
  19. End Sub
  20.  
  21. Sub HideAllButXRowsBtwnPivots()
  22. '--Hides blank rows between two PivotTables.
  23.  
  24. Dim lPivot1LastRow As Long, lPivot2FirstRow As Long
  25. Const lRowsBtwn As Long = 12
  26.  
  27. '---Get last row of top PivotTable
  28. With ActiveSheet.PivotTables("PivotTable1").TableRange2
  29. lPivot1LastRow = .Row + .Rows.Count - 1
  30. End With
  31.  
  32. '---Get first row of bottom PivotTable
  33. With ActiveSheet.PivotTables("PivotTable2").TableRange2
  34. lPivot2FirstRow = .Row
  35. End With
  36.  
  37. '--UnHide rows in-between
  38. If lPivot1LastRow + 1 < lPivot2FirstRow Then _
  39. Rows(lPivot1LastRow + 1 & ":" & lPivot2FirstRow - 1).Hidden = False
  40.  
  41. '--Hide all but specified number of rows in-between
  42. If lPivot1LastRow + 1 + lRowsBtwn < lPivot2FirstRow Then
  43. Rows(lPivot1LastRow + 1 + lRowsBtwn & _
  44. ":" & lPivot2FirstRow - 1).Hidden = True
  45. End If
  46. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement