Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. 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: Conditionally Deleting Rows.
When you are working with data tables containing information that you received from another person, you may want to prune the amount of data in the table by deleting rows if a particular condition is met. There are several ways you can approach such a task.
The first method is to use Excel's AutoFilter feature. This works particularly well if you have a rather simple criteria by which to delete rows. When you turn on the AutoFilter, Excel places pull-down buttons at the right side of each cell in the data table's header row. Using these pull-down buttons you can specify the records you want displayed. You should select a filter value that will result in displaying only those rows you want to delete. With those rows displayed, you can select them and use the ribbon tools to get rid of the rows. When you turn AutoFilter off, then you are left with only the rows you wanted.
Another method involves the use of macros to do the deleting for you. This approach works well if you have to perform the deletions on lots of data, or if you do it quite often. The following macro can delete rows based on a key value:
Sub DeleteRows()
Dim sToDelete As String
Dim ThisRow As Integer
Dim ThatRow As Integer
Dim ThisCol As Integer
Dim J As Integer
Dim iDeleted As Integer
sToDelete = InputBox("Value to Trigger Delete?", "Delete Rows")
With Selection
ThisRow = .Row
ThatRow = ThisRow + .Rows.Count - 1
ThisCol = .Column
For J = ThatRow To ThisRow Step -1
If Cells(J, ThisCol) = sToDelete Then
Rows(J).EntireRow.Delete
iDeleted = iDeleted + 1
End If
Next J
End With
MsgBox "Number of deleted rows: " & iDeleted
End Sub
To use the macro, select the key range that covers the rows you want checked. For instance, if the key to be checked is in column G, and you want to check rows 5 through 73, then you would select the range G5:G73. When you run the macro, it asks you what value it should check for. If any cells in the range G5:G73 contain the value you specify, the corresponding row for that cell is deleted.
Remember that if you use the macro to delete rows, those rows are permanently deleted. This could be a drawback in some situations. If so, you should rely on the AutoFilter technique, or make a copy of your worksheet before running the macro.
There are obviously other ways to delete rows based on a value. For a good selection of different methods, take a look at this page:
https://www.ozgrid.com/VBA/VBACode.htm
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12256) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Conditionally Deleting Rows.
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 2019 For Dummies today!
Excel allows you to easily paste information into a worksheet, including through simply dragging and dropping the ...
Discover MoreWant to use the maximum space possible for displaying information on screen? You'll want to learn how to use the ...
Discover MoreFew things are as frustrating as trying to delete rows or columns and having Excel tell you that you can't perform the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2026-06-10 10:57:10
J. Woolley
Re. my previous comment below, the macro's limitations can be reduced if the following statement
If Cells(J, ThisCol) = sToDelete Then
is replaced by this statement
If Cells(J, ThisCol).Text = sToDelete Then
In this case the "Value to Trigger Delete" key is compared with each cell's appearance instead of its underlying value.
It should be noted the macro will fail if an entire column is selected before it is initiated. If several contiguous columns are selected, only the left-most column applies. If several non-contiguous columns are selected, only the left-most column of the columns selected first applies.
Finally, the result might be unsatisfactory if it contains formulas that reference rows that were deleted.
2026-06-09 14:43:35
J. Woolley
@Alan Cannon
Perhaps you misunderstood the Tip's explanation of its DeleteRows macro.
The macro assumes contiguous cells in a single column are selected before it is initiated. It iterates over those cells, deleting a row if the cell's value matches the "Value to Trigger Delete" key. It does not iterate over columns for each row. Please review the paragraph that appears immediately after the macro.
Unfortunately, the macro only works with numeric or text cells containing the key value, not with cells containing logical values (TRUE/FALSE), error values (like #N/A), or dates.
2026-06-09 09:19:22
Alan Cannon
If the desired value can be in more than 1 column, this macro is good. But, since the macro deletes the entire row, if we assume the selection criteria is always in a single column, simply select the cells in that column for the desired row range, then revise the macro given to eliminate the iteration over columns for each row.
2022-11-21 16:39:50
Julie
This is pretty handy. Something I figured out today - if you're going to use this with a big workbook/lots of calculations, changing calculation to Manual first is a good idea.
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 © 2026 Sharon Parq Associates, Inc.
Comments