Created
August 7, 2019 13:37
-
-
Save palikhov/1155481b8b95f97b223d831fc1f56b01 to your computer and use it in GitHub Desktop.
VBA script to hide empty rows between two pivot tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub hideRowsBetweenListObjects(sheetName As String) | |
Dim tblRowPosition1 As Integer | |
Dim tblNrOfRows1 As Integer | |
Dim tblRowPosition2 As Integer | |
Dim tblNrOfRows2 As Integer | |
'Initialize | |
Application.ScreenUpdating = False | |
With Worksheets(sheetName).ListObjects(1) | |
tblRowPosition1 = .Range.Row | |
tblNrOfRows1 = .Range.Rows.Count | |
End With | |
With Worksheets(sheetName).ListObjects(2) | |
tblRowPosition2 = .Range.Row | |
tblNrOfRows2 = .Range.Rows.Count | |
End With | |
With Worksheets(sheetName) | |
If tblRowPosition1 < tblRowPosition2 Then | |
.Range(.Cells(tblRowPosition1 + tblNrOfRows1, 1), .Cells(tblRowPosition2 - 4, 1)).EntireRow.Hidden = True | |
ElseIf tblRowPosition2 < tblRowPosition1 Then | |
.Range(.Cells(tblRowPosition2 + tblNrOfRows2, 1), .Cells(tblRowPosition1 - 4, 1)).EntireRow.Hidden = True | |
End If | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment