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

Getting Rid of Empty Rows after Importing

Written by Allen Wyatt (last updated December 12, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


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.
  4. Choose Blanks and then click OK. Excel selects only those cells in the column that are blank.
  5. Choose Delete from the Edit menu. Excel displays the Delete dialog box.
  6. 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 (7986) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Quick AutoFill Variations

The AutoFill feature can be used for more than just incrementing information into cells. This tip explains how to access ...

Discover More

Aligning Numbered Lists on the Period

When you convert a paragraph to a numbered list, Word adds a number at the start of the paragraph, as you would expect. ...

Discover More

Cannot View Multiple Pages at Once

What do you do when a ribbon tool you rely upon suddenly disappears? That's the situation addressed in this tip, where ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Changing Links

If your worksheet is linked to data in other worksheets, you may need to change the link from time to time. Here's how to ...

Discover More

Excel Applies Scientific Notation to Imported Data

Using Excel to import data from another source (such as a database) is a great approach to analyze that data. What do you ...

Discover More

Converting Imported Information to Numeric Values

If the information you import into Excel is treated as text by the program, you may want to convert it to numeric values. ...

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 two less than 9?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.