Advertisement
sinancetinkaya

HideRows

Jul 10th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.83 KB | None | 0 0
  1. Sub HideRowsColumns()
  2.     ' This code hides rows and columns if all cells within the range are empty.
  3.     Set rows_ = ActiveSheet.UsedRange.Rows
  4.    
  5.     For Each row_ In rows_
  6.         is_empty = True
  7.         For Each cell_ In row_.Cells()
  8.             If Not IsEmpty(cell_) Then is_empty = False: Exit For
  9.         Next cell_
  10.         If is_empty Then row_.EntireRow.Hidden = True
  11.     Next row_
  12.    
  13.     Set columns_ = ActiveSheet.UsedRange.Columns
  14.     For Each column_ In columns_
  15.         is_empty = True
  16.         For Each cell_ In column_.Cells()
  17.             If Not IsEmpty(cell_) Then is_empty = False: Exit For
  18.         Next cell_
  19.         If is_empty Then column_.EntireColumn.Hidden = True
  20.     Next column_
  21. End Sub
  22.  
  23. Sub UnHideRowsColumns()
  24.     Columns.EntireColumn.Hidden = False
  25.     Rows.EntireRow.Hidden = False
  26. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement