Clear rows in excel

Excel for Microsoft 365 Excel 2021 Excel 2019 Excel 2016 Excel 2013 Excel 2010 Excel 2007 More…Less

You can clear cells to remove the cell contents (formulas and data), formats (including number formats, conditional formats, and borders), and any attached comments. The cleared cells remain as blank or unformatted cells on the worksheet.

  1. Select the cells, rows, or columns that you want to clear.

    Tip: To cancel a selection of cells, click any cell on the worksheet.

  2. On the Home tab, in the Editing group, click the arrow next to the Clear button Button image, and then do one of the following:

    • To clear all contents, formats, and comments that are contained in the selected cells, click Clear All.

    • To clear only the formats that are applied to the selected cells, click Clear Formats.

    • To clear only the contents in the selected cells, leaving any formats and comments in place, click Clear Contents.

    • To clear any comments or notes that are attached to the selected cells, click Clear Comments and Notes.

    • To clear any hyperlinks that are attached to the selected cells, select Clear Hyperlinks.

Notes: 

  • If you click a cell and then press DELETE or BACKSPACE, you clear the cell contents without removing any cell formats or cell comments.

  • If you clear a cell by using Clear All or Clear Contents, the cell no longer contains a value, and a formula that refers to that cell receives a value of 0 (zero).

  • If you want to remove cells from the worksheet and shift the surrounding cells to fill the space, you can select the cells and delete them. On the Home tab, in the Cells group, click the arrow next to Delete, and then click Delete Cells.

Need more help?

Easy Ways to Remove Blank or Empty Rows in Excel

by Avantix Learning Team | Updated April 5, 2021

Applies to: Microsoft® Excel® 2010, 2013, 2016, 2019, 2021 and 365 (Windows)

You can delete blank rows in Excel using several tricks and shortcuts. Check out these 5 fast ways to remove blank or empty rows in your worksheets.

In this article, we’ll focus on methods that work with all versions of Excel. In future articles, we’ll take a look at other methods available in Excel 365.

Here, we’re assuming your data is in ranges of cells with data arranged vertically below row headings or field names (and no merged cells). Excel recognizes data arranged in this way as a list or data set (or database). You can also use many of these strategies with Excel tables.

Recommended article: 15 Microsoft Excel Keyboard Shortcuts to Speed Up Formatting

Do you want to learn more about Excel? Check out our virtual classroom or live classroom Excel courses >

If you want to delete one row, you can delete the row manually:

  1. Select the row. Click its heading or select a cell in the row and press Shift + spacebar.
  2. Right-click the selected row heading. A drop-down menu appears.
  3. Select Delete.

1. Deleting blank rows using the context menu

To delete multiple contiguous blank rows using the context menu:

  1. Drag across the row headings using a mouse or select the first row heading and then Shift-click the last row heading.
  2. Right-click one of the row headings. A drop-down menu appears.
  3. Select Delete.

To delete multiple non-contiguous blank rows using the context menu:

  1. To select non-contiguous rows, click the heading of the first row and then Ctrl-click the headings of the other rows you want to select.
  2. Right-click one of the row headings. A drop-down menu appears.
  3. Select Delete.

2. Deleting blank rows using a keyboard shortcut

To delete multiple contiguous blank rows using a keyboard shortcut:

  1. Drag across the row headings using a mouse or select the first row heading and then Shift-click the last row heading.
  2. Press Ctrl + – (minus sign at the top right of the keyboard) to delete the selected rows.

To delete multiple non-contiguous blank rows using a keyboard shortcut:

  1. To select non-contiguous rows, click the heading of the first row and then Ctrl-click the headings of the other rows you want to select.
  2. Press Ctrl + – (minus sign at the top right of the keyboard) to delete the selected rows.

3. Deleting blank rows by sorting

An easy way to delete blank rows is to sort the data so that blanks appear at the bottom and you can then ignore them.

To delete blank rows by sorting:

  1. Select the entire range of data (not just the column you want to sort).
  2. Click the Data tab in the Ribbon.
  3. Select Sort in the Sort & Filter group. A dialog box appears. Assuming you have a header row, select My data has headers.
  4. Beside Sort by, select the field or column with the blanks you want to remove and then select the appropriate sorting option (such as A-Z, smallest to largest, ascending or descending) to display blanks at the bottom of the data set.
  5. Click OK. Blank rows will now appear at the bottom of the data set and can be ignored.

Below is the Sort dialog box:

Sort dialog box in Excel to sort and remove or delete blank rows.

4. Deleting blank rows using Go to Special to highlight blanks

A great way to remove blank rows in a range of data is to use Go to Special.

The Go To Special dialog box displays the following options:

 Excel Go to Special dialog box to find and delete blank rows.

To find and remove blank rows using Go to Special:

  1. Select one column where there are blank cells in the column (we’re assuming here that the rest of the row is blank). If there is sensitive data above or below the list that you don’t want to delete, select the cells in the column from the first cell in the range to the last cell in the range (you could click in the first cell and Shift-click in the last cell).
  2. Press Ctrl + G. The Go To dialog box appears.
  3. Click Special to display the Go To Special dialog box. Alternatively, you can click the Home tab in the Ribbon and then select Go To Special from the Find & Select drop-down menu.
  4. Select Blanks in the Go to Special dialog box and click OK. Excel will select all of the blank cells within the selected range.
  5. Right-click one of the selected blank cells and select Delete. A dialog box appears.
  6. Select Entire Row.
  7. Click OK.

The Delete dialog box appears as follows:

 Excel dialog box to delete blank rows after right-clicking.

Although you can also use the Find command to find blanks, it’s much easier to use Go to Special.

5. Deleting blank rows using filtering

You can also delete blank rows using filtering (traditionally called AutoFiltering).

To delete blank rows using Filter:

  1. Select the range of cells that includes all of the data in the data set (including blank rows).
  2. Click the Data tab in the Ribbon.
  3. Select Filter in the Sort & Filter group. Alternatively, you can press Ctrl + Shift + L. Arrows appear beside the field names.
  4. Click the arrow beside the field name with the blank cells in  rows you want to delete.
  5. Turn off or de-select Select All.
  6. Select Blanks. You will likely need to scroll down to select Blanks.
  7. Select the row headings of the filtered rows by clicking the first row heading and Shift-clicking the last row heading.
  8. Right-click one of the selected headings. A drop-down menu appears.
  9. Select Delete Row.
  10. Click the Data tab in the Ribbon and select Clear in the Sort & Filter group to remove the filtering.

In the example below, the Promotion field is filtered to display blanks:

Display blanks using Filter in Excel to remove or delete blank rows.

You will now be able to sort, filter and create pivot tables with the list.

Subscribe to get more articles like this one

Did you find this article helpful? If you would like to receive new articles, JOIN our email list.

More resources

How to Use Flash Fill in Excel (4 Ways with Shortcuts)

How to Lock Cells in Excel (Protect Formulas and Data)

3 Excel Strikethrough Shortcuts to Cross Out Text or Values in Cells

Use Conditional Formatting in Excel to Highlight Dates Before Today (3 Ways)

How to Replace Blank Cells in Excel with Zeros (0), Dashes (-) or Other Values

Related courses

Microsoft Excel: Intermediate / Advanced

Microsoft Excel: Data Analysis with Functions, Dashboards and What-If Analysis Tools

Microsoft Excel: Introduction to Power Query to Get and Transform Data

Microsoft Excel: New and Essential Features and Functions in Excel 365

Microsoft Excel: Introduction to Visual Basic for Applications (VBA)

VIEW MORE COURSES >

Our instructor-led courses are delivered in virtual classroom format or at our downtown Toronto location at 18 King Street East, Suite 1400, Toronto, Ontario, Canada (some in-person classroom courses may also be delivered at an alternate downtown Toronto location). Contact us at info@avantixlearning.ca if you’d like to arrange custom instructor-led virtual classroom or onsite training on a date that’s convenient for you.

Copyright 2023 Avantix® Learning

Microsoft, the Microsoft logo, Microsoft Office and related Microsoft applications and logos are registered trademarks of Microsoft Corporation in Canada, US and other countries. All other trademarks are the property of the registered owners.

Avantix Learning |18 King Street East, Suite 1400, Toronto, Ontario, Canada M5C 1C4 | Contact us at info@avantixlearning.ca

Blank rows of data can be a big annoyance.

They’ll make certain things like navigating around our data much more difficult.

But the good news is there are lots of ways to get rid of these unwanted rows and it can be pretty easy to do it.

In this post, we’re going to take a look at 9 ways to remove blank rows from our Excel data.

Delete Blank Rows Manually

The first method is the manual way.

Don’t worry, we’ll get to the easier methods after. But if we only have a couple rows then the manual way can be quicker.

Select the blank rows we want to delete. Hold Ctrl key and click on a row to select it.

When the rows we want to delete are selected then we can right click and choose Delete from the menu.

We can also delete rows using a ribbon command. Go to the Home tab ➜ click on the Delete command ➜ then choose Delete Sheet Rows.

There is also a very handy keyboard shortcut to delete rows (columns or cells). Press Ctrl + on the keyboard.

That’s it! Our blank rows are gone now.

Delete Blank Rows Using Go To Special

Selecting and deleting rows manually is OK if we only have a couple rows to delete.

What if there are many blank rows spread across our data? Manual selection would be a pain!

Don’t worry, there is a command in Excel to select all the blank cells for us.

First, we need to select a column of our data including all the blank rows. The easiest way to do this will be to select the first cell (A1 in this example) then hold the Shift key and select the last cell (A14 in this example).

Now we can use the Go To Special command to select only the blank cells. Go to the Home tab ➜ press the Find & Select command ➜ choose Go To Special from the menu.

There’s also a handy keyboard shortcut for the Go To menu. Press Ctrl + G to open up the Go To menu then click on the Special button to open up the Go To Special menu.

Whether we open up the Go To menu then click Special or we go directly to the Go To Special menu, we will arrive at the same Go To Special menu.

Now all we need to do is select Blanks from the options and press the OK button.  This will select only the blank cells from our initial column selection.

Now we need to delete those selected rows.

  1. Use any delete rows method from the Delete Blank Rows Manually section.
    • Right click ➜ Delete
    • Home tab ➜ Delete ➜ Delete Sheet Rows
    • Ctrl + keyboard shortcut
  2. In the Delete menu select Entire row and press the OK button.

Like magic, we can find and delete hundreds of blank rows in our data within a few seconds. This is especially nice when we have a lot of blank rows scattered across a long set of data.

Delete Blank Rows Using Find Command

This method is going to be very similar to the above Delete Blank Rows Using Go To Special method. The only difference is we will select our blank cells using the Find command.

Just like before, we need to select a column in our data.

Go to the Home tab ➜ press the Find & Select command ➜ choose Find from the menu.

There is also a keyboard shortcut we can use to open the Find menu. Press Ctrl + F on the keyboard.

Either way, this will open up the Find & Replace menu for us.

  1. Expand the Advanced options in the Find menu.
  2. Leave the Find what input box blank.
  3. Select the Match entire cell contents option.
  4. Search Within the Sheet.
  5. Look in the Values.
  6. Press the Find All button to return all the blank cells.

This will bring up a list of all the blank cells found in the selected range at the bottom of the Find menu.

We can select them all by pressing Ctrl + A. Then we can close the Find menu by pressing the Close button. Now we can delete all the blank cells like before.

Delete Blank Rows Using Filters

We can also use filters to find blank rows and delete them from our data.

First, we need to add filters to our data.

  1. Select the entire range of data including the blank rows.
  2. Go to the Data tab.
  3. Press the Filter button in the Sort & Filter section.

We can also add filters to a range by using the Ctrl + Shift + L keyboard shortcut.

This will add sort and filter toggles to each of the column headings and we can now use these to filter out the blank.

  1. Click on the filter toggle on one of the columns.
  2. Use the Select All toggle to de-select all items.
  3. Check the Blanks.
  4. Press the OK button.

When our data is filtered, the row numbers appear in blue and filtered rows are numbers are missing.

We can now select these blank rows with the blue row numbering and delete them using any of the manual methods.

We can then press the OK button when Excel asks us if we want to Delete entire sheet row.

When we clear the filters, all our data will still be there but without the blank rows!

We can use filters in a slightly different way to get rid of the blank rows. This time we will filter out the blanks. Click on the filter toggle on one of the columns ➜ uncheck the Blanks ➜ press the OK button.

Now all our blank rows are hidden and we can copy and paste our data to a new location without all the blank rows.

Delete Blank Rows Using Advanced Filters

Similar to filter method, we can use the Advanced Filters option to get a copy of our data minus any blank rows.

To use the Advanced Filters feature, we’re going to need to do a bit of setup work.

  1. We need to set up a filter criteria range. We are only going to filter based on one column, so we need one column heading from our data (in F1 in this example). Below the column heading we need our criteria (in F2 in this example), we need to enter ="" into this cell as our criteria.
  2. Select the range of data to filter.
  3. Go to the Data tab.
  4. Select Advanced in the Sort & Filter section.

Now we need to configure the Advanced Filter menu.

  1. Select Copy to another location.
  2. Select the range of data to be filtered. This should already be populated if the range was selected before opening the advanced filters menu.
  3. Add the criteria to the Criteria range (F1:F2 in this example).
  4. Select where in the sheet to copy the filtered data.
  5. Press the OK button.

We now get a copy of our data in its new location without the blanks.

Delete Blank Rows Using The Filter Function

If we are using Excel online or Excel for Office 365, then we can use one of the new dynamic array functions to filter out our blank rows.

In fact, there is a dynamic array FILTER function we can use.

FILTER Function Syntax

= FILTER ( Array, Include, [Empty] )
  • Array is the range of data to filter.
  • Include is a logical expression indicating what to include in the filtered results.
  • Empty is the results to display if no results based on the Include argument are found.

FILTER Function To Filter Blanks

= FILTER ( CarData, CarData[Make]<>"" )

The above function needs to be entered in only one cell and the results will spill into the remaining cells as needed. The function will filter the CarData on the Make column and filter out any blanks.

It’s easy and the great part is it’s dynamic. Because our data is in an Excel table, when we add new data into the CarData table, it will appear in our filtered results.

Delete Blank Rows By Sorting

In addition to all the filtering techniques, we can sort our data to get all the blank rows.

  1. Select the range of data.
  2. Go to the Data tab.
  3. Press the sort command. Either the ascending or descending order will work.

Now all our blank rows will appear at the bottom and we can ignore them.

If we need the original sort order of our data, we can add an index column before sorting. Then we can sort to get the blank rows at the bottom and delete them. Then we sort our data back to the original order based on the index column.

Delete Blank Rows Using Power Query

Power can easily remove blank rows in our data.

This is great is we keep getting updated data with blanks in it and need to include this in our data preparation steps.

Once our data is inside the power query editor, we can easily remove our blank data. Notice, these appear as null values inside the editor.

  1. Go to the Home tab in the power query editor.
  2. Press the Remove Rows button.
  3. Select the Remove Blank Rows option from the menu.
= Table.SelectRows(#"Changed Type", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))

This will generate the above M code using the Table.SelectRows function to select the non-null rows. This will only remove rows where the entire record has null values.

We could also get the same result by filtering out the null values in our data. Right click on any of the sort and filter toggles then uncheck the null value and press the OK button.

= Table.SelectRows(#"Changed Type", each ([Model] <> null))

Power query will again generate a step with the Table.SelectRows function, returning non-null values in a specific column.

Delete Blank Rows Using Power Automate

This one might not be as quick, easy and practical as the other methods but it can be done.

We can use Power Automate to delete blank rows in our Excel tables.

In order to do this with Power Automate, we will need to have our data in an Excel table and it will need an ID column that uniquely identifies each row.

We can set up a small Flow automation to do this.

  1. We will use a manual button to trigger our flow, but we could use any number of triggers.
  2. We then need to List rows present in a table to get all the rows of data from our Excel table. The best option would also be to use the Odata filters in the Show advanced options section to filter on the blank rows, but this is currently not possible to filter on blanks.
  3. Because we can’t filter on the blank values with Odata filters, we need to use a Filter array data operation action to do this. We can filter on the values from the List rows present in a table action and set the condition as Make is equal to blank (leave the value empty). This will get us all the rows with blank cells.
  4. We can now use the Delete a row action to delete these blank rows. We can select our ID column as the Key Column and then add the ID field from the Filter array action. This should wrap the action in an Apply to each step to delete all the blanks.

When this automation runs, it will delete any blank rows the table has.

Conclusions

Blank rows in our data can be a nuisance.

Removing them is easy and we have lots of options.

My favourite way is probably the Go To keyboard shortcut method. It’s quick, easy and does the job.

Did I miss any methods? Let me know in the comments below!

About the Author

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Adding and deleting rows is part of everyday common tasks when working with Excel.

While you can do this easily from the worksheet itself, sometimes you may want to use the VBA route to delete rows in Excel. These could be deleting a specific row, multiple rows in the selection, deleting alternate rows or those that have a specific value in it.

In this tutorial, I will show you how to delete rows in Excel using VBA (multiple scenarios).

So let’s get started!

Delete an Entire Row using VBA

To delete an entire row in Excel using VBA, you need to use the EntireRow.Delete method.

For example, if you want to delete the entire first row in a worksheet, you can use the below code:

Sub DeleteEntireRow()
Rows(1).EntireRow.Delete
End Sub

The above code first specifies the row that needs to be deleted (which is done by specifying the number in bracket) and then uses the EntireRow.Delete method to delete it.

You can also delete multiple rows by specifying these rows in the code.

For example, the below code will delete row number 1, 5 and 9 in the worksheet:

Sub DeleteEntireRow()
Rows(9).EntireRow.Delete
Rows(5).EntireRow.Delete
Rows(1).EntireRow.Delete
End Sub

The above code uses the same logic, where it specifies the row numbers and Excel will delete these rows one by one.

IMPORTANT: When you’re deleting rows with something similar to the above code, remember to start deleting from the bottom and then go up. For example, in case you start at the top and delete row 1 first, all the rows below it would be shifted one row up and the numbering would be off (as row 5 would become row 4 and so on)

Delete All Rows in the Selection

In case you want to delete all the rows in a selected range of cells, you can use the VBA macro code below:

Sub DeleteEntireRow()
Selection.EntireRow.Delete
End Sub

The above code applies to the EntireRow.Delete method to the entire selection.

Delete Alternate rows (or Delete Every Third/Fourth/Nth Row)

Sometimes, you may get a data dump where every second row (or third, fourth or Nth rows) is useless and needs to be deleted.

I used to work with financial data where every second row was empty and had to be deleted.

This is the type of scenario where VBA really shines.

Below is the VBA code that will go through all the rows in the selection and delete every second row:

Sub DeleteAlternateRows()
RCount = Selection.Rows.Count
For i = RCount To 1 Step -2
    Selection.Rows(i).EntireRow.Delete
Next i
End Sub

Let me explain how this VBA code works.

First, I have used a variable RCount to get the total number of rows in the selection.

Then I have used a For Next loop to run this as many times as many rows are there. For example, if there are 12 rows, this loop will run from 12 to 1 (i.e., 12 times). It’s important to run this from the last row in the selection to the first as we don’t want the row numbers to change when a row is deleted.

Also, Step -2 is used since we need to delete every other row (from bottom to top). In case you want to delete every third row, you can use -3.

Within the VBA loop, I have used the Selection.Rows(i).EntireRow.Delete method to delete every alternate row.

Delete Blank Rows with VBA

You can also use the EntireRow.Delete method to delete all blank rows.

Below is the VBA code that will select blank cells in the selected dataset and delete the entire row.

Sub DeleteBlankRows()
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

The above code uses the SpecialCells property to select and delete all the cells that are blank. This is the same method that also allows us to use ‘Go To Special’ dialog box to select all blank cells.

Once these blank cells are identified using SpecialCell, these are then deleted using the EntireRow.Delete method.

Note: This method selects cells that are blank and don’t check whether the entire row is blank or not. So if anyone cell is empty in a row, this would still delete the entire row.

Delete Rows with a Specific Word/Value

You can also use a simple VBA code to go through each cell in the selected range and delete all the rows where a cell contains a specific text or value.

For example, suppose you have a dataset and I want to delete all cells that have the text Printer in column 2 of the selection.

Dataset from where delete entire row with specific value

Below is the code that will do this:

Sub DeleteRowswithSpecificValue()
For i = Selection.Rows.Count To 1 Step -1
If Cells(i, 2).Value = "Printer" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
End Sub

The above code first counts the total number of rows in the selection. This will make sure the loop is run only these many times. It then uses the ‘For Next loop’ to go through all the cells in Column 2.

The IF THEN ELSE statement is then used to check the value in each cell in column 2. And in case the value/text matches the specified text (which is ‘Printer’ in this example).

In this example, I have checked whether the text matches a specific string or not. You can also do this with values. For example, you can delete all rows where the sale value is less than 1000 or more than 1000.

Note: An important thing to note here is that the loop runs from Selection.Rows.Count To 1 to make sure when a row is deleted, it doesn’t impact the rows above it.

How to Use This VBA Code

Now let me show you how to use all the codes mentioned in this tutorial to delete the entire row.

You need to copy and paste these codes in a module in Excel VB Editor. Once you have these codes copied, you can then run the macro codes.

Below are the steps to copy and paste these VBA codes in a module:

  1. Hold the ALT key and press the F11 key (or Function + Option + F11 in Mac). This will open the VB Editor
  2. In the VB Editor, you will have the project explorer on the left. If you don’t see it, go to the View option and then click on Project Explorer.Click on Project Explorer
  3. Right-click on any object in the Project Explorer (for the workbook in which you want to run the code).Insert Module
  4. Go to Insert and then click on Module. This will insert a new Module for the workbookCopy and paste to delete entire row in the module
  5. Copy and Paste the above codes in the module.

And to run these codes, you can place the cursor anywhere in the code (that you want to run) and hit the F5 key (or click on the green triangle in the VBA toolbar).

I have also written a detailed tutorial on different ways to run VBA macro codes in Excel.

In case you need to use any of these codes quite often, you can also consider adding these to the Personal Macro Workbook and then to the QAT. This way, the code will be available to you in any of your workbooks with a single click.

So these were some VBA codes that you can use to delete entire rows in Excel (in different scenarios). The same logic can also be applied in case you want to delete columns instead of rows (with the corresponding adjustment in the code examples).

Hope you found this tutorial useful!

You may also like the following Excel tutorials:

  • Excel VBA Autofilter: A Complete Guide with Examples
  • Delete Rows Based on a Cell Value (or Condition) in Excel
  • Insert a Blank Row after Every Row in Excel (or Every Nth Row)
  • How to Quickly Unhide COLUMNS in Excel

Bottom line: Learn a few ways to delete blank rows in Excel from a data set or table. Includes video tutorial and VBA macro.

Skill level: Beginner

Watch on YouTube & Subscribe to our Channel

Download the File

Download the example Excel file to follow along.  The file also contains the Select Blank Rows macro.

3 Ways to Find & Delete Blank Rows

If you are exporting reports from any type of system then there is a good chance the data contains blank rows.  One very common task we do in Excel is to delete these blank rows from the worksheet, especially if you are preparing your data for use with a pivot table.

How do we find and delete entire blank rows

In this case we want to delete rows that are entirely blank.  If a row contains a few blank cells, we still want to keep that row of data.

There are several ways to accomplish this task.  Let’s look at some ways to save time and make this process easy.

#1 – Filter for Blanks

If our data set contains a column that ONLY has blank cells in the blank rows, then we can filter for blanks on that column.

Filter a column for blanks

In our example file we can filter the Customer column for blanks.  We can see that rows 4 & 9 still contain data in the other columns.  Therefore we do NOT want to delete these rows.

Filter for Blanks in a column leaves some data rows visible

You can continue to filter other columns for blanks until all cells in the range or Table are blank.  However, this can be time consuming if you have a lot of columns in your data set.

Once you have a filter applied that makes only the entire blank rows visible, then select and delete the rows.  The rows can be deleted by pressing the Delete button on the Home tab of the ribbon (keyboard shortcut: Ctrl+-)

Delete Filtered Blank Rows

Checkout my 3-part video series on Excel Filters to learn more time saving shortcuts.

#2 – Use a Formula to Identify Entire Blank Rows

Another approach is to use a formula with the COUNTA function.  The COUNTA function returns the count of cells that are NOT empty in a range.

We can add this formula to the right of the table, and copy down to each row in the table.

This will give us a column of values that returns the number of empty or non-blank cells in the row.  If the formula returns a 0 (zero) then all the cells in that row are blank.

COUNTA Formula to Count Cells that are NOT Empty or Blank

We then filter the new column for 0 (zero).  This will show all of the entire blank rows, and hide all non-blank rows.

Filter for Zero in the COUNTA column to View All Blank Rows

Next we just select and delete the visible rows.

Select and Delete Blank Rows based on COUNTA formula column

To recap, the steps to delete entire blank rows are:

  1. Add a column with the COUNTA formula to count non-blank cells.
  2. Filter the column for 0 (zero).
  3. Select all visible rows in the filter range.
  4. Delete the rows with the Ctrl+- keyboard shortcut.
  5. Clear the filter to view all rows.

I use an Excel Table (Beginner’s Guide to Tables) in this example, and highly recommend using Tables.  You can turn off the Table Formulas (structured references) if you don’t like them.

#3 – Use a Macro to Select or Delete Entire Blank Rows

The fastest approach to deleting blank rows is to use a macro.  This allows us to perform the entire task with a click of a button.

The following macro will select all the entire blank rows in the selected range.  If you only have a single cell selected, the macro finds all blank rows in the UsedRange of the active sheet.

Macro to Select All Entire Blank Rows to Delete

Sub Select_Blank_Rows()
'Select all entire blank rows in selected range
'Source: https://www.excelcampus.com/tips/delete-entire-blank-rows/

Dim rRow As Range
Dim rSelect As Range
Dim rSelection As Range
 
  'Check that a range is selected
  If TypeName(Selection) <> "Range" Then
    MsgBox "Please select a range first.", vbOKOnly, "Select Blank Rows Macro"
    Exit Sub
  End If
  
  'Check that multiple cells are selected
  If Selection.Cells.Count = 1 Then
    Set rSelection = ActiveSheet.UsedRange
  Else
    Set rSelection = Selection
  End If
 
  'Loop through each row and add blank rows to rSelect range
  For Each rRow In rSelection.Rows
    If WorksheetFunction.CountA(rRow) = 0 Then
      If rSelect Is Nothing Then
        Set rSelect = rRow
      Else
        Set rSelect = Union(rSelect, rRow)
      End If
    End If
  Next rRow
  
  'Select blank rows
  If rSelect Is Nothing Then
    MsgBox "No blank rows were found.", vbOKOnly, "Select Blank Rows Macro"
    Exit Sub
  Else
    rSelect.Select
  End If
  
End Sub

The macro only selects the blank rows. We can then manually delete the rows with the Ctrl+- keyboard shortcut or pressing the Delete button on the Home tab of the Ribbon.

You can replace the following line of code:

rSelect.Select

with this line of code if you would rather have the macro delete the blank rows.

rSelect.Rows.Delete Shift:=xlShiftUp

It’s important to note that you will NOT be able to undo the delete action. So I prefer to have the macro just select the blank rows, and then delete them manually. That way I can undo the action if needed.

If you do add the code to delete the row, I’d recommend adding a Yes/No Message Box to the macro to prevent you from running it accidentally.

The macro can also be modified to select blank columns instead of rows.

Change the following line of code:

For Each rRow In rSelection.Rows</pre>

To:
For Each rRow In rSelection.Columns

The macro will loop through all the columns and select the blank columns in the selected or used range.  Thanks to Sandy for suggesting this!

The Select Blank Rows macro can be added to your Personal Macro Workbook (video guide to creating your Personal Macro Workbook).  We can also add a custom macro button to the ribbon to quickly run the macro on any open workbook.

Other Methods to Delete Blank Rows?

One other method is to use the Go To Special window to select blanks.  We can use this instead of filtering a column for blanks.

Go To Special Menu Select Blank Cells

Here are the steps to use the Go To Special window to select and delete blank rows:

  1. Select an entire column in the worksheet.  The column must ONLY contain blank cells where the entire row is blank.
  2. On the Home tab, click the Find & Select button, then choose Go To Special… (keyboard shortcut: F5, Alt+S)
  3. Select the Blanks radio button on the Go To Special window. (keyboard shortcut: k, Enter)
  4. Delete the entire row.  Home tab > Delete (keyboard shortcut: Ctrl+-)

It’s important to note that this method suffers from the same potential as solution #1.  If the column contains blank cells where the entire row is NOT blank, then this will not work.

What other methods do you use for deleting blank rows?  Please share by leaving a comment below.  Thank you! 🙂

Понравилась статья? Поделить с друзьями:
  • Circle the word that is different straight long blonde beard
  • Clear excel cells with vba
  • Circle the word that is different socks gloves trainers sandals
  • Clear columns in word
  • Circle the word that is different prawns mussels duck squid