Written by Allen Wyatt (last updated April 29, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
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:
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:
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, Excel in Microsoft 365, and 2021.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
When setting up a worksheet for others to use, you might want to make some limitations on what can be entered in certain ...
Discover MoreAs you enter data in a worksheet, you may want to have Excel automatically move from cell to cell based on the length of ...
Discover MoreYou may be looking for a way to have a formula determine if a particular cell has anything in it. Here's how you can find ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments