Table of Contents
This short formal description explains the process of using VBA (Visual Basic for Applications) in Excel to delete empty rows. VBA is a programming language used to automate tasks in Excel. To delete empty rows, users can create a VBA macro that loops through each row and checks if it is empty. If it is, the macro will delete the entire row. This method allows for a quick and efficient way to clean up large amounts of data in Excel spreadsheets. By utilizing VBA, users can save time and effort compared to manually deleting empty rows one by one.
Delete Empty Rows in VBA (With Examples)
You can use the following methods in VBA to delete empty rows:
Method 1: Delete Empty Rows in Specific Range
Sub DeleteEmptyRowsInRange()
Sheets("Sheet1").Select
Range("A1:B10").Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
This particular macro will delete all empty rows in the range A1:B10 of Sheet1.
Method 2: Delete Empty Rows in Entire Sheet
Sub DeleteEmptyRowsInSheet()
'turn off screen updating for faster performance
Application.ScreenUpdating = False
Dim i As Long
With ActiveSheet
For i = .Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If WorksheetFunction.CountA(.Rows(i)) = 0 Then
ActiveSheet.Rows(i).Delete
End IfNextEnd With'turn screen updating back on
Application.ScreenUpdating = True
End Sub
This particular macro will delete all empty rows in the entire active sheet.
The following examples show how to use each method in practice.
Example 1: Delete Empty Rows in Specific Range
Suppose we have the following dataset in Excel that contains information about various basketball players:

We can create the following macro to delete all empty rows in the range A1:B10 on this sheet:
Sub DeleteEmptyRowsInRange()
Sheets("Sheet1").Select
Range("A1:B10").Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End SubOnce we run this macro, we receive the following output:

Notice that all empty rows have been deleted from the range that we specified.
Example 2: Delete Empty Rows in Entire Sheet

We can create the following macro to delete all empty rows in the entire sheet:
Sub DeleteEmptyRowsInSheet()
'turn off screen updating for faster performance
Application.ScreenUpdating = False
Dim i As Long
With ActiveSheet
For i = .Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If WorksheetFunction.CountA(.Rows(i)) = 0 Then
ActiveSheet.Rows(i).Delete
End IfNextEnd With'turn screen updating back on
Application.ScreenUpdating = True
End SubOnce we run this macro, we receive the following output:

Notice that all empty rows have been deleted from the entire sheet.
Cite this article
stats writer (2024). How can I delete empty rows using VBA in Excel?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-delete-empty-rows-using-vba-in-excel/
stats writer. "How can I delete empty rows using VBA in Excel?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-delete-empty-rows-using-vba-in-excel/.
stats writer. "How can I delete empty rows using VBA in Excel?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-delete-empty-rows-using-vba-in-excel/.
stats writer (2024) 'How can I delete empty rows using VBA in Excel?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-delete-empty-rows-using-vba-in-excel/.
[1] stats writer, "How can I delete empty rows using VBA in Excel?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I delete empty rows using VBA in Excel?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
