Monday, December 22, 2014

Excel VBA - Delete All Blank Lines in Work Sheet

Following subroutine deletes all blank lines from current work sheet from the bottom with the range defined A1:Z50.

Sub DeleteRowsFromBottom()
Dim range As range, rows As Integer, i As Integer
  
Set range = ActiveSheet.range("A1:Z50")
rows = range.rows.Count
For i = rows To 1 Step (-1)
    If WorksheetFunction.CountA(range.rows(i)) = 0 Then range.rows(i).Delete
Next

End Sub

No comments: