Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub hideRows()
- 'Opens/unhides all groups
- ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8
- 'Ungroups all Rows and Columns
- Range("A1:A3000").ClearOutline 'Rows
- Range("A1:DZ1").ClearOutline 'Columns
- 'Uses GetFalseRowRange function to group all rows with FALSE condition
- Dim falseRowRange As Range
- Dim grp As Range
- Set falseRowRange = GetFalseRowRange(Range("B1", Cells(Rows.Count, 1).End(xlUp).Offset(1)))
- If Not falseRowRange Is Nothing Then
- For Each grp In falseRowRange.Areas '<--| group contiguous cells toghether
- grp.Rows.Group
- Next
- End If
- 'Uses GetFalseColumnRange
- Dim falseColumnRange As Range
- Dim grp2 As Range
- Set falseColumnRange = GetFalseColumnRange(Range("A1", Cells(1, Columns.Count).End(xlToLeft)))
- If Not falseColumnRange Is Nothing Then
- For Each grp2 In falseColumnRange.Areas '<--| group contiguous cells toghether
- grp2.Columns.Group
- Next
- End If
- 'Closes all groups
- ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
- End Sub
- 'GetFalseRowRange function groups all rows that are false
- Function GetFalseRowRange(rng As Range) As Range
- With rng
- .AutoFilter field:=1, Criteria1:=CStr(False), Operator:=xlAnd, Criteria2:="<>"
- If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then Set GetFalseRowRange = .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible)
- .Parent.AutoFilterMode = False
- End With
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement