VBA macro to delete empty rows in excel sheet. This macro does below steps
- It selects “A1” cell i.e. first row
- It asks the user to enter the number of rows that he wants to check
- It checks whether row is empty or not
- if the row is empty, then it deletes the entire row and the cursor moves to next row
- Else it moves to the next row
- 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") Range("A1").Select Do ' syntax to check whether a row is empty If Application.CountA(ActiveCell.EntireRow) = 0 Then ' syntax to delete a row Selection.EntireRow.Delete Else 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