Sometimes we need to delete the entire row which contains blank cell from a table. Though we can delete them by right click on row index and just ‘Delete’ them manually, if they are not adjacent or the table is very long, to delete rows manually is very troublesome. As there are a lot of powerful features built in Excel, actually we can delete rows via these features. In this free tutorial, we will introduce you to delete entire rows contain blank cells from a spreadsheet by two ways via Go To Special function and VBA Macro.
See screenshot below. There are two blank cells exist in this table. As they are invalid, so we need to remove the two rows.
Method 1: Delete Entire Rows by Go To Special function
Step 1: Select the table. Then click Home in the ribbon, click Find & Select icon under Editing group, and select Go To Special option. See screenshot below.
In this step, you can also press F5 to load Go To dialog, and click Special button to load Go To Special dialog as well.
Step 2: On Go To Special dialog, check on Blank option. Then click OK.
Step 3: After above operating, blank cell rows are auto selected.
Step 4: Right click on one of the select rows, click Delete.
Step 5: On Delete dialog, check on Entire row. Then click OK.
Step 6: Check the updated table. Verify that rows contain blank cells are deleted.
Method 2: Delete Entire Rows by VBA Macro
Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View Code, Microsoft Visual Basic for Applications window pops up.
Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic. You can also press Alt + F11 keys simultaneously to open it.
Step 2: In Microsoft Visual Basic for Applications window, click Insert->Module, enter below code in Module1:
Sub DeleteEntireRow() Dim SelectRng As Range On Error Resume Next xTitleId = "Delete Entire Row" Set SelectRng = Application.Selection Set SelectRng = Application.InputBox("Please select your range", xTitleId, SelectRng.Address, Type:=8) Set SelectRng = SelectRng.SpecialCells(xlCellTypeBlanks) If Err = 0 Then SelectRng.EntireRow.Delete End If End Sub
Step 3: Save code and quit Microsoft Visual Basic for Applications.
Step 4: Click Developer->Macros to run Macro. Select ‘DeleteEntireRow’ and click Run.
Step 5: Delete Entire Row dialog pops up. Select range $A$2:$B$16. Click OK. In this step you can select the range you want to do delete rows with blank cells.
Step 6: Click OK and check the result. Verify that we get the same result as method1.