Deleting Rows before a Cutoff Date

Written by Allen Wyatt (last updated April 29, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365


Barry has a large worksheet containing several thousand rows of data. Column B contains a date, and he needs to delete all the rows in which the date in column B is earlier than a specific cutoff date. Barry wonders about the easiest way to do this for so much data.

This is rather easy to do, with the approach you use dependent on how often you need to do it and how you want to work with your data. If you don't care what order your data is in, then the easiest method is what I refer to as the "sort and delete" method:

  1. Select cell B2. (This assumes that B2 is the first date in your rows of data because row 1 contains headers.)
  2. Display the Data tab of the ribbon.
  3. Click the Sort Oldest to Newest tool. Excel sorts the data according to the dates in column B, with the oldest date in row 2.
  4. Select and delete the rows that contain dates before your cutoff.

This works great if you only need to perform that task once in a while and if you don't mind the rows in the data being reordered. If reordering is a problem, then you may want to add a column to your data and fill that column with values from 1 to however many rows of data you have. You can then perform the "sort and delete" method, but afterwards resort your data based on the values in the column you added.

Of course, you could also use a "filter and delete" method, which will leave your data in its original order without the need of a helper column:

  1. Select cell B2. (This assumes that B2 is the first date in your rows of data because row 1 contains headers.)
  2. Press Ctrl+Shift+L. Excel applies AutoFilter to your data. (You should be able to see the small drop-down arrows next to the headers in row 1.)
  3. Click the drop-down arrow next to the Date header in cell B1. Excel displays some sorting and filtering options.
  4. Hover your mouse pointer over the Date Filters option. Excel displays even more options.
  5. Choose the Before option. Excel displays the Custom AutoFilter dialog box.
  6. In the box to the right of "Is Before," specify a date one day after your cutoff date.
  7. Click OK. Excel applies the filter and you can only see those rows that are at or before your cutoff date.
  8. Select all the rows, but not row 1. (That's because row 1 contains your headers.)
  9. Display the Home tab of the ribbon.
  10. Click the Delete tool. Excel deletes all the selected rows.
  11. Display the Data tab of the ribbon.
  12. Click the Filter tool to remove the AutoFilter.

If you need to perform the task of removing rows often, then you won't be able to beat the convenience of using a macro. The following macro assumes that you've placed the cutoff date into cell K1. It grabs this date and then looks at each row in your data, deleting any rows that are before this cutoff date.

Sub DeleteRowsBeforeCutoff()
    Dim LastRow As Integer
    Dim J As Integer

    Application.ScreenUpdating = False
    LastRow = Cells(Rows.Count, 2).End(xlUp).Row
    For J = LastRow To 1 Step -1
        If Cells(J, 2) < [K1] Then
            Cells(J, 2).EntireRow.Delete
        End If
    Next J
    Application.ScreenUpdating = True
End Sub

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (1566) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365.

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

Margin Notes in Word

Some types of documents rely upon margin notes to the left or right of your main text. Getting these to appear in Word ...

Discover More

Merge and Center Not Available

What are you to do if you are trying to format a worksheet, only to find out that one of the tools you need is not ...

Discover More

Understanding the Personal Workbook Filename

The personal macro workbook is a great place to save your macros that you want to use with any workbook. The personal ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Previous Column Values in a Drop-Down List

Want a quick way to add non-unique values into a column? You probably know you can do this by starting to simply type in ...

Discover More

Converting Text to Values

When you import information originating in a different program, Excel may not do the best job at figuring out what ...

Discover More

Splitting Sentences to Cells

If you have a lot of text in your workbook, at some point you might want to split out sentences into individual cells. ...

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 three more than 1?

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 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.