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: Deleting Old Data from a Worksheet.

Deleting Old Data from a Worksheet

Written by Allen Wyatt (last updated June 11, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


Gene is looking for a way to quickly delete data from a worksheet based on the date in a particular column. If the date is older than today (the date is passed) then the row should be deleted.

This can be rather easily done with a macro. All you need to do have the macro step through the data and compare the date in each row to today's date. If the date is less than today, then the Delete method is used on the EntireRow object.

Sub DeleteRows1()
    Dim x As Long
    Dim iCol As Integer

    iCol = 7 'Filter all on Col G

    For x = Cells(Cells.Rows.Count, iCol).End(xlUp).Row To 2 Step -1
        If Cells(x, iCol).Value < Date Then
            Cells(x, iCol).EntireRow.Delete
        End If
    Next
End Sub

In this example, the macro checks column G (in the iCol variable) for the date. If your date is in a different column, then you should make the change to the variable. Depending on the number of rows of data in your worksheet, the macro may also take quite a while to run.

If you notice a lag in performance, then you may want to use a different approach. The following example uses the AutoFilter capabilities of Excel to first filter the data to show only the old data, and then deletes those rows.

Sub DeleteRows2()
    Dim Dates As Range
    Dim nRows As Double
    Dim currDate As Variant

    'Format dates as text
    Range("Dates").NumberFormat = "@"
    'Today's date in number format
    currDate = CDbl(Date)
    Range("Dates").AutoFilter Field:=1, _
      Criteria1:="<" & currDate
    nRows = Range("Dates").Rows.Count
    Rows("2:" & nRows).Select
    Selection.Delete Shift:=xlUp
    Range("Dates").AutoFilter
    Range("Dates").NumberFormat = "m/d/yyyy"
    Range("C2").Select
End Sub

This macro presumes that you have taken the step of assigning a name to your data range. Select all the cells in your data table—including any heading row—and give it the name "Dates." When you run the macro, it uses this range as the target for the AutoFilter.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3384) 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: Deleting Old Data from a Worksheet.

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

Getting the Name of the Worksheet Into a Cell

Excel allows you to change the names assigned to the worksheets in a workbook. If you want to have those names appear in ...

Discover More

Protecting Your Revisions

Want to protect your documents so that people can't edit them without you knowing about it? One way is to make sure that ...

Discover More

Years in Which a Date Occurred on a Particular Day

If you need to know the years in which a particular date occurred on a specific day of the week, there are a number of ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Cleaning Up Lists

When you have huge amounts of data you need to check for matches, Excel may not be the best tool to use. If you can fit ...

Discover More

Limiting Choices in a Cell

Want to limit what a person can enter into a particular cell? You can use Excel's data validation feature to help enforce ...

Discover More

How Many Rows and Columns Have I Selected?

Want a quick way to tell how may rows and columns you've selected? Here's what I do when I need to know that information.

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 5 - 3?

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.