Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. Private Sub hideRowsBetweenListObjects(sheetName As String)
  2. Dim tblRowPosition1 As Integer
  3. Dim tblNrOfRows1 As Integer
  4. Dim tblRowPosition2 As Integer
  5. Dim tblNrOfRows2 As Integer
  6.  
  7. 'Initialize
  8. Application.ScreenUpdating = False
  9.  
  10. With Worksheets(sheetName).ListObjects(1)
  11. tblRowPosition1 = .Range.Row
  12. tblNrOfRows1 = .Range.Rows.Count
  13. End With
  14.  
  15. With Worksheets(sheetName).ListObjects(2)
  16. tblRowPosition2 = .Range.Row
  17. tblNrOfRows2 = .Range.Rows.Count
  18. End With
  19.  
  20. With Worksheets(sheetName)
  21. If tblRowPosition1 < tblRowPosition2 Then
  22. .Range(.Cells(tblRowPosition1 + tblNrOfRows1, 1), .Cells(tblRowPosition2 - 4, 1)).EntireRow.Hidden = True
  23. ElseIf tblRowPosition2 < tblRowPosition1 Then
  24. .Range(.Cells(tblRowPosition2 + tblNrOfRows2, 1), .Cells(tblRowPosition1 - 4, 1)).EntireRow.Hidden = True
  25. End If
  26. End With
  27. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement