VBA – Delete Blank Rows

Delete Blank Rows

The obvious way to remove blank rows from a data set is to simply sort the data. This moves the blank rows to the bottom of the data and “removes” them. But what if you want the blank rows removed, however you don’t want the data sorted? VBA.

The following macro will remove blank rows without any sorting (turn off screen updating to go faster).

Sub DeleteBlankRows()

Dim x As Long

With ActiveSheet

    For x = .Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
        If WorksheetFunction.CountA(.Rows(x)) = 0 Then
            ActiveSheet.Rows(x).Delete
        End If
    Next

End With

End Sub

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

 

Learn More!


<<Return to VBA Examples

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)