Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Sub hideRows()
  4.  
  5. 'Opens/unhides all groups
  6.  
  7. ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8
  8.  
  9. 'Ungroups all Rows and Columns
  10. Range("A1:A3000").ClearOutline 'Rows
  11. Range("A1:DZ1").ClearOutline 'Columns
  12.  
  13. 'Uses GetFalseRowRange function to group all rows with FALSE condition
  14.  
  15. Dim falseRowRange As Range
  16. Dim grp As Range
  17.  
  18. Set falseRowRange = GetFalseRowRange(Range("B1", Cells(Rows.Count, 1).End(xlUp).Offset(1)))
  19.  
  20. If Not falseRowRange Is Nothing Then
  21. For Each grp In falseRowRange.Areas '<--| group contiguous cells toghether
  22. grp.Rows.Group
  23. Next
  24. End If
  25.  
  26. 'Uses GetFalseColumnRange
  27. Dim falseColumnRange As Range
  28. Dim grp2 As Range
  29.  
  30. Set falseColumnRange = GetFalseColumnRange(Range("A1", Cells(1, Columns.Count).End(xlToLeft)))
  31.  
  32. If Not falseColumnRange Is Nothing Then
  33. For Each grp2 In falseColumnRange.Areas '<--| group contiguous cells toghether
  34. grp2.Columns.Group
  35. Next
  36. End If
  37. 'Closes all groups
  38.  
  39. ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
  40.  
  41.  
  42. End Sub
  43.  
  44. 'GetFalseRowRange function groups all rows that are false
  45.  
  46. Function GetFalseRowRange(rng As Range) As Range
  47. With rng
  48. .AutoFilter field:=1, Criteria1:=CStr(False), Operator:=xlAnd, Criteria2:="<>"
  49. If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then Set GetFalseRowRange = .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible)
  50. .Parent.AutoFilterMode = False
  51. End With
  52.  
  53. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement