Advertisement
tom

Clear all empty rows in all sheets

tom
Jul 14th, 2016
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' sauce: http://stackoverflow.com/a/9379968/6338845
  2. Option Explicit
  3.  
  4. Sub DeleteEmptyRows()
  5.     Dim i As Long
  6.     Dim DelRange As Range
  7.  
  8.     On Error GoTo Whoa
  9.  
  10.     Application.ScreenUpdating = False
  11.  
  12.     For i = 1 To 500
  13.         If Application.WorksheetFunction.CountA(Range("A" & i & ":" & "Z" & i)) = 0 Then
  14.             If DelRange Is Nothing Then
  15.                 Set DelRange = Rows(i)
  16.             Else
  17.                 Set DelRange = Union(DelRange, Rows(i))
  18.             End If
  19.         End If
  20.     Next i
  21.  
  22.     If Not DelRange Is Nothing Then DelRange.Delete shift:=xlUp
  23. LetsContinue:
  24.     Application.ScreenUpdating = True
  25.  
  26.     Exit Sub
  27. Whoa:
  28.     MsgBox Err.Description
  29.     Resume LetsContinue
  30. End Sub
  31.  
  32. ' sauce: https://support.microsoft.com/en-us/kb/142126
  33.      Sub CleanAllEmptyRows()
  34.  
  35.          ' Declare Current as a worksheet object variable.
  36.         Dim Current As Worksheet
  37.  
  38.          ' Loop through all of the worksheets in the active workbook.
  39.         For Each Current In Worksheets
  40.  
  41.             ' Insert your code here.
  42.            ' This line displays the worksheet name in a message box.
  43.            Call DeleteEmptyRows
  44.          Next
  45.  
  46.       End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement