Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Getting Rid of Empty Rows after Importing.

Getting Rid of Empty Rows after Importing

by Allen Wyatt
(last updated March 9, 2016)

8

There are numerous times when Tom has a worksheet imported from another program into Excel so he can work with the data. The importing works fine, but the import process adds lots (dozens and sometimes hundreds) of extra rows that have no data in them. After the import Tom has to manually delete those extra rows so he can use the rest of the data. Tom wonders if there is a way to easily get rid of these empty rows.

There are a number of ways you can approach this problem. The easiest way may be to simply sort the imported data by the column of your choice. All the rows that contain nothing in that column end up at either the end or beginning of the data (depending on if you sort in ascending or descending order) and you can easily delete those rows.

Obviously, when you do a sort in this manner you could end up with your data out of the original, imported order. If you need your data to be in the original order—but with the blank rows removed—just insert a column to the left or right of your data, fill it with sequential numbers, perform the sort by any column except that added column, and then delete the rows that are blank (with only something in the numbering column). You can then sort a second time based on the numbering column and your data will be back in its original order.

Another approach is to follow these steps:

  1. Select an entire column.
  2. Press F5. Excel displays the Go To dialog box.
  3. Click Special. Excel displays the Go To Special dialog box. (See Figure 1.)
  4. Figure 1. The Go To Special dialog box.

  5. Choose Blanks and then click OK. Excel selects only those cells in the column that are blank.
  6. Choose Delete from the Edit menu. Excel displays the Delete dialog box.
  7. Choose Entire Row and then click OK.

If you prefer to use a macro to get rid of the blank rows, you can use something similar to the following:

Sub DeleteEmptyRows()
    Dim LastRow As Long
    Dim J As Long

    LastRow = ActiveSheet.UsedRange.Rows.Count + _
      ActiveSheet.UsedRange.Rows(1).Row - 1
    Application.ScreenUpdating = False
    For J = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountA(Rows(J)) = 0 Then
            Rows(J).Delete
        End If
    Next J
    Application.ScreenUpdating = True
End Sub

Why would you want to use a macro? Because you may need to delete empty rows week after week. Just put the macro into your Personal workbook and you can then access it whenever you need.

Additional information on this topic can be found on these pages:

http://www.cpearson.com/Excel/deleting.htm#DeleteBlankRows
http://dmcritchie.mvps.org/excel/lastcell.htm

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7988) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Getting Rid of Empty Rows after Importing.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Creating Point Pages

Want to add a page, with a different page number, in Word without affecting the entire document? The solution is a bit ...

Discover More

Smart Quotes are Incorrectly Replaced

Not able to replace smart quotes as you want? Here are some ways that you can be sure that every smart quote is changed, ...

Discover More

Countering Compressed Columns

If you open a workbook and find that the width of some of your columns has been changed, the discovery can be frustrating. ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Loading Unwanted Files at Startup

Imagine how painful it would be if every time you started Excel it tried to load all the files in your root directory? That ...

Discover More

Getting Rid of Extra Quote Marks in Exported Text Files

If you don't like the way that Excel exports information you intend to use with other programs, then your best bet is to ...

Discover More

Use Filenames that Sort Properly

When storing your Excel workbook, you need to specify a file name to be used for the workbook. Take a moment to consider how ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 1?

2017-01-05 00:08:16

Krishna

It Really Works.
Thnaks...


2017-01-05 00:05:35

Murali

Nice article


2016-03-10 12:11:25

Jake

I use below all the time and have it set in my QAT. This one looks at the selected column and if there is a blank cell in the column it will delete the entire row.

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


2016-03-09 17:26:57

Scott Laursen

I use variations on this bit of code often to delete unwanted rows. Select a cell or cells in the one column that has data for the rows you want to keep and run it. This deletes blanks, but mess around with the AutoFilter Criteria and you can delete or retain anything with a particular value.

Sub DeleteBlanks()
Dim iColumn As Integer
iColumn = Selection.Column
'check that only one column is selected
If Selection.Columns.Count > 1 Then End
With ActiveSheet
.Rows(1).Insert
.Cells(1, iColumn).Value = "Temp"
.Cells.AutoFilter Field:=Cells(1, iColumn).Column, Criteria1:="="
.Cells(iColumn, iColumn).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
End Sub


2016-03-09 09:55:38

Dennis Westbrooks

What if the column you select has blank cells, but the adjacent cell two columns over has data, wouldn't this delete the data?


2016-03-09 07:25:48

Jim Morrison

There is a great add-in for Excel called ASAP utilities. One of the many things it allows you to do with only a couple of clicks is to delete empty rows or columns. Highly recommended (and free for non-commercial use)


2014-04-17 08:25:14

Surendera M. Bhanot

Good one again. This situation is encountered too often by too many. The solution provided here will go a long way to such disturbed souls. Thanks Allen


2014-04-16 11:57:10

C.R. Mundaca

Too many links that did not have clear explanation. You were the only with easier how to steps.

Thank you


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.