VBA – Delete Blank Rows

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 12, 2022

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 is one method of doing this, or you can delete blank rows using the COUNTA Function and deleting filtered cells.

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
        End If

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!)

Free Download

Return to VBA Code Examples