VBA macro to delete empty rows [excel]

VBA macro to delete empty rows in excel sheet. This macro does below steps

  1. It selects “A1” cell i.e. first row
  2. It asks the user to enter the number of rows that he wants to check
  3. It checks whether row is empty or not
  4. if the row is empty, then it deletes the entire row and the cursor moves to next row
  5. Else it moves to the next row
  6. repeats steps 3 to 5 for remaining rows (step 2)


VBA macro to delete empty rows

Sub deleteEmptyRows()
Dim rowCount As Variant
rowCount = InputBox("Enter number of rows that you want to check")
' syntax to check whether a row is empty
If Application.CountA(ActiveCell.EntireRow) = 0 Then
' syntax to delete a row
ActiveCell.Offset(1, 0).Select
End If
rowCount = rowCount - 1
Loop Until rowCount = 0
End Sub

If you want a VBA macro to delete entire row if cell is empty in a particular column, click here

About the Author


A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published. Required fields are marked *