Deleting Rows Containing Struck-Through Text

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


1

Tara often receives workbooks containing a single worksheet where some information in the worksheet contains text that is "struck through" (the text is formatted using strikethrough). Rows that contain struck-through text need to be deleted, but Tara isn't sure of how to quickly go about this.

If you only need to do this task once in a while, the following steps will help you out if it is easy to see which cells contain the strike-through formatting:

  1. Click at the left side of the first row you want to select—the first one containing struck-through text. The entire row should be selected.
  2. Hold down the Ctrl key as you click at the left side of any additional rows you want to delete. (You are building a selection set of rows to delete.)
  3. Press Ctrl+- (the minus key). The rows are deleted.

If it is not that easy to see all the rows containing struck-through text, you can rely on the Find feature to locate them for you:

  1. Press Ctrl+F. Excel displays the Find tab of the Find and Replace dialog box.
  2. Click the Options button to expand what is available in the dialog box.
  3. Make sure the Find What box is empty and place the insertion point within that box.
  4. Click the Format button. Excel displays the Find Format dialog box.
  5. Make sure the Font tab is visible. (It will probably be displayed by default.)
  6. Click the Strikethrough check box a time or two until you see it is selected. (You shouldn't need to change anything else in the dialog box.)
  7. Click OK to dismiss the Find Format dialog box.
  8. Click Find All. The Find and Replace dialog box expands to show which cells contain strikethrough formatting, and the first result (in the dialog box) is selected.
  9. Press Ctrl+A. This selects all the results in the dialog box.
  10. Click Close to dismiss the Find Format dialog box. All the cells containing strikethrough text should now be selected. (Don't click anywhere else in the worksheet or you'll inadvertently unselect the cells.)
  11. Press Ctrl+- (the minus key). Excel displays the Delete dialog box.
  12. Click the Entire Row radio button.
  13. Click OK. The rows are deleted.

There is a drawback to this approach—it won't find any cells containing mixed formatting. In other words, if only some of the text within the cell uses the strikethrough attribute, then that cell won't be found in step 8.

This deficiency can be overcome by using a macro. Plus, a macro is a good approach if you need to perform this task quite often. Here's one that will do the trick:

Sub DeleteSTRows()
    Dim c As Range
    Dim bCheck As Boolean
    Dim J As Integer
    Dim iRows As Integer

    iRows = Selection.Rows.Count
    If iRows > 2 Then
        For J = iRows To 1 Step -1
            bCheck = False
            For Each c In Selection.Rows(J).Cells
                bCheck = IsNull(c.Font.Strikethrough)
                If Not bCheck Then bCheck = c.Font.Strikethrough
                If bCheck Then Exit For
            Next c
            If bCheck Then Selection.Rows(J).EntireRow.Delete
        Next J
    End If
End Sub

To use the macro, simply select the cells you want to affect, and then run it. The macro steps through each row of the selection (from the last row to the first) and then checks each cell within those rows. If the cell contains struck-through text, then a flag (bCheck) is set and the entire row is deleted. (The macro won't work if your selection contains only 1 or 2 rows—that few of rows is easy enough to check and adjust manually.)

Note in the middle of the macro that the IsNull function is used. This is the part that detects if the cell contains mixed formatting. If only some of the characters in the cell use strike-through, then a null value is returned by the Strikethrough property. This is checked by IsNull and assigned to the bCheck variable. If bCheck is still False (meaning that there is no mixed use of strike-through in the cell), then the entire cell is checked to see if it has the requisite formatting.

It should be noted that if you don't want the macro to actually delete rows, but would prefer to just clear them, you can replace the .Delete method in the macro with the .Clear method.

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

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

Hiding and Unhiding Columns

Want to hide a column so it doesn't appear in the worksheet? It's easy to do using the formatting capabilities of Excel.

Discover More

Setting Orientation of Cell Values

Need the contents of a cell to be shown in a direction different than normal? Excel makes it easy to have your content ...

Discover More

Can't Select Style Instances

Using the Styles and Formatting task pane, Word allows you to select all instances of a given style in your document. ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Understanding Auto-Population of Cells

Auto-population of your formulas can be a useful tool when you are adding data to your worksheets. It would be even more ...

Discover More

Identifying Duplicates

Do you need to flag duplicate values in your data? This tip shows three different ways you can do the flagging you need.

Discover More

Not Enough Resources to Delete Rows and Columns

Few things are as frustrating as trying to delete rows or columns and having Excel tell you that you can't perform the ...

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

2024-05-15 10:04:04

J. Woolley

Re. the Tip's macro, I have some nits to pick:
1. From the Tip: "The macro won't work if your selection contains only 1 or 2 rows—that few of rows is easy enough to check and adjust manually." Is this really necessary?
2. A cell formatted with Strikethrough font will trigger deletion even if that cell is empty or blank ("").
3. Rows containing Strikethrough font are deleted without confirmation even if they were originally hidden.
4. Possibly hidden columns are not considered.
The following version addresses these issues:

Sub DeleteSTRows2()
    Dim sele As Range, cell As Range, nCols As Long, n As Long
    Dim hideCols() As Boolean, hideRow As Boolean, strike As Variant
    If Not (TypeOf ActiveSheet Is Worksheet) Then Exit Sub
    Set sele = Application.Intersect(Selection, ActiveSheet.UsedRange)
    If sele Is Nothing Then Exit Sub
    nCols = sele.Columns.Count
    ReDim hideCols(nCols)
    For n = 1 To nCols
        hideCols(n) = sele.Columns(n).Hidden 'original status
        sele.Columns(n).Hidden = False 'make visible
    Next n
    For n = sele.Rows.Count To 1 Step -1
        With sele.Rows(n)
            For Each cell In .Cells 'for each cell in this row
                If cell.Value <> "" Then
                    strike = cell.Font.Strikethrough
                    If strike Or IsNull(strike) Then 'full or partial
                        hideRow = .Hidden 'original status
                        .Hidden = False 'make visible
                        .Cells(1).Show
                        .Select
                        If MsgBox("Delete this row?", vbYesNo) = vbYes Then
                            .EntireRow.Delete
                        Else
                            .Hidden = hideRow 'restore original
                        End If
                        Exit For 'finished with this row
                    End If
                End If
            Next cell
        End With
    Next n
    For n = 1 To nCols
        sele.Columns(n).Hidden = hideCols(n) 'restore original
    Next n
    sele.Select 'remainder of original selection
End Sub


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.