Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub HideRowsColumns()
- ' This code hides rows and columns if all cells within the range are empty.
- Set rows_ = ActiveSheet.UsedRange.Rows
- For Each row_ In rows_
- is_empty = True
- For Each cell_ In row_.Cells()
- If Not IsEmpty(cell_) Then is_empty = False: Exit For
- Next cell_
- If is_empty Then row_.EntireRow.Hidden = True
- Next row_
- Set columns_ = ActiveSheet.UsedRange.Columns
- For Each column_ In columns_
- is_empty = True
- For Each cell_ In column_.Cells()
- If Not IsEmpty(cell_) Then is_empty = False: Exit For
- Next cell_
- If is_empty Then column_.EntireColumn.Hidden = True
- Next column_
- End Sub
- Sub UnHideRowsColumns()
- Columns.EntireColumn.Hidden = False
- Rows.EntireRow.Hidden = False
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement