A dataset in Excel containing blank rows is challenging to read and navigate and can lead to computational errors.
Therefore, we must remove the empty rows to resolve such problems. This tutorial shows you five techniques for removing blank rows in Excel.
Note: We recommend you back up your workbook before applying any of the following methods to remove rows from your dataset. This safeguard ensures that you can revert to your original data in case data is deleted unintentionally.
Method #1: Remove Blank Rows By Manually Selecting and Deleting
In this method, we manually select all the blank rows and delete them.
We use the following dataset, which has three blank rows (4, 8, and 12), to illustrate how this technique works.
To delete the blank rows 4, 8, and 12 from the dataset, use the following steps:
- Click the numeric header of row number 4 to select the entire row.
- Press and hold down the Control key, click the numeric row headers of rows 8 and 12 to select the rows, and then release the Control key.
- Right-click the selection and click Delete on the shortcut menu that appears.
The three blank rows are removed from the dataset:
Note: This manual method is okay for small datasets but inconvenient for large ones with tens or hundreds of blank rows.
We recommend removing blank rows from large datasets using the following techniques.
Also read: How to Remove Blank Columns in Excel? (Formula + VBA)
Method #2: Remove Blank Rows Using Find and Replace + Formula
This method involves using a formula and the Find and Replace dialog box to select all the blank rows from the dataset and then delete them.
We use the following dataset, which has three blank rows (4, 8, and 12), to illustrate how this technique works.
We use the below steps:
- Insert a helper column by selecting column A (click the column header), right-click the column, and select Insert on the shortcut menu that appears.
- Select cell A1 in the helper column and type in the following formula:
=IF(COUNTA(B1:XFD1)=0,"Blank","Not Blank")
- Click the Enter button on the Formula bar to enter the formula.
- Drag the fill handle to copy the formula down the column.
Notice that the formula has returned “Blank” in the first cell of all the blank rows (4, 8, and 12).
- Select the cell range A1:A14 and press Ctrl + F to open the Find and Replace dialog box.
- On the Find and Replace dialog box that appears and do the following:
- Open the Find tab.
- Type “Blank” (without quotation marks) in the Find what box.
- Open the Within drop-down and select Sheet.
- Open the Search drop-down and select By Rows.
- Open the Look in drop-down and choose Values.
- Select the Match entire cell contents option.
- Click the Find All button.
The Find and Replace feature finds all the cells that contain “Blank” and displays their cell references at the bottom of the dialog box.
- Press Ctrl + A to select all the cells that contain “Blank.”
The cell references at the bottom of the Find and Replace dialog box are highlighted in blue, and the cells containing “Blank” in the dataset are selected.
- Click the Close button to close the Find and Replace dialog box.
- Right-click any of the selected cells in the dataset and select Delete on the shortcut menu that appears:
- Select the Entire row option on the Delete dialog box that appears and click OK.
All the blank rows are deleted, and data is shifted upwards:
- Delete the helper column.
We now have our dataset minus the blank rows.
Explanation of the formula
=IF(COUNTA(B1:XFD1)=0,”Blank”,”Not Blank”)
The formula combines the IF and COUNTA functions.
The COUNTA function computes the number of non-empty cells in the range B1:XFD1.
The function begins counting from cell B1 because cell A1 contains a formula and is part of the helper column.
The function stops counting at cell XFD1 because that is the last cell in the row and is part of column XFD which is the last column in the worksheet.
If the value returned by the COUNTA function equals zero (0), the row is blank, and the IF function returns the value “Blank.”
Conversely, if the number returned by the COUNTA function is not equal to zero (0), the row is not blank, and the IF function returns “Not Blank.”
Also read: How to Delete Multiple Rows in Excel?
Method #3: Delete Blank Rows Using Formula + Sorting
In this method, we use a formula to identify the blank rows and then use the Sort option to group them before deleting them.
This method is handy if you want to delete non-adjacent blank rows.
We use the following dataset, which has three blank rows (4, 8, and 12), to illustrate how this technique works.
We use the following steps:
- Insert a helper column by selecting column A (click the column header), right-click the column, and select Insert on the shortcut menu that appears.
- Select cell A1 in the helper column and type in the following formula:
=IF(COUNTA(B1:XFD1)=0,"Blank","Not Blank")
- Click the Enter button on the Formula bar to enter the formula.
- Drag the fill handle to copy the formula down the column.
Notice that the formula has returned “Blank” in the first cell of all the blank rows (4, 8, and 12).
- Select the cell range A1:A14 in the helper column.
- On the Data tab, in the Sort & Filter group, click the Sort button.
- Select the Expand the selection option on the Sort Warning dialog box that appears and click the Sort button.
- Click the Options button on the Sort dialog box that appears.
- Select the Sort top to bottom option on the Sort Options dialog box that appears, and then click the OK button.
- Do the following on the Sort dialog box:
- Open the Column Sort by drop-down and select Not Blank (This is the header of the helper column).
- Open the Sort on drop-down and select Cell Values.
- Open the Order drop-down and choose A to Z.
- Click OK.
All the blank rows are grouped at the top of the dataset:
- Select row 2 by clicking its numeric row header, press and hold down the Shift key, select row 4, which is the last blank row, then release the Shift key.
- Right-click the selected blank rows and select Delete on the shortcut menu that appears:
The blank rows are deleted, and the data is shifted upwards:
- Delete the helper column.
The helper column is deleted, and data is shifted to the left.
We now have our dataset without the blank rows.
Method #4: Remove Blank Rows Using Power Query
We can use Excel’s Get & Transform feature to remove blank rows from a dataset.
This feature, however, converts the source range into an Excel table and changes the formatting, such as number formats.
Therefore, if you want to keep your dataset’s original formatting, use the other methods in this tutorial.
We use the following dataset, which has three blank rows (4, 8, and 12), to demonstrate how this method works.
We use the below steps:
- Select the entire dataset.
- On the Data tab, in the Get & Transform Data group, click From Table/Range.
The Create Table dialog appears.
Notice that the Get & Transform Data feature has correctly guessed the dimensions of the data range and its headers.
If the guess is wrong, you can make the needed adjustments.
- Click OK on the Create Table dialog box.
The dataset is converted to an Excel Table, and the Power Query Editor is launched.
- On Power Query Editor’s Home tab, in the Reduce Rows group, open the Remove Rows drop-down and select the Remove Blank Rows option.
- Click the Close & Load button.
The Power Query Editor is closed, and the resulting table is loaded to a new worksheet.
Method #5: Delete Empty Rows Using Excel VBA Script
This method involves creating a sub-routine in Excel VBA and then running it to delete empty rows from a dataset.
We use the following dataset, which has three blank rows (4, 8, and 12), to show how this technique works.
We use the following steps:
- Open the active worksheet containing the dataset.
- On the Developer tab, in the Code group, click Visual Basic to open the Visual Basic Editor.
Alternatively, press Alt + F11 to open the Visual Basic Editor.
- In the Visual Basic Editor, open the Insert menu and select Module to insert a module.
- Please copy the following code and paste it into the module.
'Code developed by Steve Scott from https://spreadsheetplanet.com
Sub removeBlankRows()
Dim focusRange As Range
Dim wholeRow As Range
Dim i As Long
On Error Resume Next
Set focusRange = Application.InputBox("Select a range:", "Remove Blank Rows", Application.Selection.Address, Type:=8)
If Not (focusRange Is Nothing) Then
Application.ScreenUpdating = False
For i = focusRange.Rows.Count To 1 Step -1
Set wholeRow = focusRange.Cells(i, 1).EntireRow
If Application.WorksheetFunction.CountA(wholeRow) = 0 Then
wholeRow.Delete
End If
Next
Application.ScreenUpdating = True
End If
End Sub
- Save the sub-routine and the workbook as a Macro-Enabled Workbook.
- Place the cursor anywhere in the sub-procedure and press F5 to execute the code.
- When the Remove Blank Rows dialog box appears, open the active worksheet and select the entire dataset.
- Press OK on the Remove Blank Rows dialog box, and you are taken back to the Visual Basic Editor.
- Click the View Microsoft Excel button on the toolbar to switch to the active worksheet.
We can also switch to the active worksheet by pressing Alt + F11.
When we look at the dataset, we see that the sub-procedure has deleted all the blank rows:
This tutorial has shown five techniques for removing blank rows in Excel. We hope you found the tutorial instructive and helpful.
Other Excel articles you may also like:
It’s still a hoot to learn something new like this, outstanding insights – I’m bookmarking your page. Thank you, Steve. I’ve managed a few tricks myself to expedite project tasks in various environments, but it’s hard to beat Excel for being the shortest path to getting the results ya need. Thanks for sharing.