Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Strikethrough: How to Apply It with Code

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can apply strikethrough in Excel VBA by setting the Strikethrough property of a Font object to True. For example, Range("A1").Font.Strikethrough = True strikes through cell A1. To remove it, set the property to False. This works on any range, and you can also toggle it based on a condition or apply it to part of a cell's text using the Characters property.

What You'll Need

  • Microsoft Excel (desktop version for Windows or Mac). VBA is not available in Excel for the web or most mobile versions.
  • Basic familiarity with the VBA editor (how to open it and insert a module).
  • Macros enabled in your workbook. If you see a security warning, you may need to enable macros for the session.

Step-by-Step

  1. Open the VBA editor. Press Alt + F11 (Windows) or Option + F11 (Mac). This opens the Visual Basic for Applications editor.
  2. Insert a new module. In the editor, go to Insert > Module. A blank code window appears.
  3. Write a simple macro to apply strikethrough. Type the following code:
    Sub ApplyStrikethrough()
        Range("A1").Font.Strikethrough = True
    End Sub
    This strikes through the entire contents of cell A1. Change "A1" to any cell or range, such as "B2:D10".
  4. Run the macro. Press F5 while the cursor is inside the subroutine, or go to Run > Run Sub/UserForm. Switch back to Excel to see the result.
  5. Remove strikethrough. Change True to False in the code and run it again. Alternatively, use Range("A1").Font.Strikethrough = False.
  6. Toggle strikethrough based on a condition. Use an If statement to apply strikethrough only when a condition is met. For example, to strike through cells in column A that contain the word "Done":
    Sub StrikeIfDone()
        Dim cell As Range
        For Each cell In Range("A1:A10")
            If cell.Value = "Done" Then
                cell.Font.Strikethrough = True
            Else
                cell.Font.Strikethrough = False
            End If
        Next cell
    End Sub
  7. Apply strikethrough to part of a cell's text. Use the Characters property to target specific characters. For example, to strike through the first 5 characters of cell A1:
    Sub StrikePartOfCell()
        With Range("A1")
            .Characters(Start:=1, Length:=5).Font.Strikethrough = True
        End With
    End Sub
    Adjust Start and Length as needed.
  8. Save your work. Save the workbook as a macro-enabled file (.xlsm) to keep the VBA code. Regular .xlsx files will discard macros.

Common Mistakes

  • Forgetting to enable macros. If macros are disabled, the code won't run. Check the security settings or enable macros for the session.
  • Using the wrong property name. The property is Strikethrough, not StrikeThrough or Strikeout. VBA is case-insensitive but spelling must be correct.
  • Applying to a protected sheet. If the worksheet is protected, you cannot change formatting. Unprotect the sheet first (Review > Unprotect Sheet).
  • Not qualifying the range. If you omit the worksheet reference, VBA uses the active sheet. That may be fine, but if you run the macro from a different sheet, it may affect the wrong cells. Use Worksheets("Sheet1").Range("A1") to be explicit.
  • Expecting strikethrough to work in Excel for the web. VBA is not supported there. Use conditional formatting or manual formatting instead.

Tips

  • To toggle strikethrough on and off, use Range("A1").Font.Strikethrough = Not Range("A1").Font.Strikethrough. This flips the current state.
  • You can apply strikethrough to an entire row or column by using Rows(1).Font.Strikethrough = True or Columns("A").Font.Strikethrough = True.
  • Combine with other font properties, such as .Font.Color = RGB(255, 0, 0), to make struck-through text more noticeable.
  • Use a loop to process many cells efficiently. For large ranges, turn off screen updating with Application.ScreenUpdating = False before the loop and set it back to True after.
  • If you need to apply strikethrough based on cell formatting (e.g., color), use the Interior.Color or Font.Color properties in your condition.

Troubleshooting

  • Macro doesn't run: Check that macros are enabled. Look for a yellow security bar and click "Enable Content". Also ensure the code is in a standard module, not a sheet module, unless you intend it to be there.
  • Error "Object required" or "Method 'Range' of object '_Global' failed": This usually means the range reference is invalid or the sheet is not active. Qualify the range with a worksheet object.
  • Strikethrough doesn't appear: The cell may be formatted as text with a font that doesn't support strikethrough (rare). Try changing the font. Also check that the cell isn't hidden or that the font color isn't the same as the background.
  • Part of cell text not struck through: The Characters method only works on text values, not formulas or numbers. Convert the cell to text first if needed.
  • Sheet is protected: Unprotect the sheet via Review > Unprotect Sheet. If you don't know the password, you'll need to contact the sheet owner.

Frequently Asked Questions

Can I apply strikethrough to multiple non-contiguous cells at once?

Yes. Use a union of ranges, e.g., Union(Range("A1"), Range("C3")).Font.Strikethrough = True. Alternatively, loop through each area.

Does strikethrough work on numbers and dates?

Yes, the Font.Strikethrough property applies to the entire cell content regardless of data type. However, the Characters method only works on text.

How do I remove strikethrough from all cells in a worksheet?

Use Cells.Font.Strikethrough = False. This clears strikethrough from every cell on the active sheet.

Can I use strikethrough in conditional formatting with VBA?

Conditional formatting does not support strikethrough directly. You can use VBA to apply strikethrough based on conditions, but it won't update automatically like conditional formatting. You'd need to re-run the macro when data changes.

Is there a keyboard shortcut for strikethrough in Excel?

Excel does not have a default keyboard shortcut for strikethrough. You can add one via the Quick Access Toolbar or use VBA. In the Font dialog (Ctrl+1), you can check the Strikethrough box.

Why does my macro work on one sheet but not another?

The macro likely references the active sheet. If you run it from a different sheet, it affects that sheet. Use explicit worksheet references like Worksheets("Sheet1").Range("A1") to avoid this.