Smart Systems for Home

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

Excel VBA Strikethrough Text: Complete Implementation Guide

· 6 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

To apply a strikethrough to text using Excel VBA, you must set the Font.Strikethrough property of a Range or a specific character set to True. For an entire cell, the simplest command is Range("A1").Font.Strikethrough = True. This allows you to automate the visual marking of completed tasks, invalidated data, or expired entries without manual formatting.

What You'll Need

  • Microsoft Excel installed on a Windows or macOS computer.
  • The Developer tab enabled in the Excel Ribbon.
  • A basic understanding of how to open the Visual Basic Editor (VBE).
  • A workbook saved in the .xlsm (Excel Macro-Enabled Workbook) format to ensure the code is preserved.

Step-by-Step

  1. Enable the Developer Tab: If you do not see the Developer tab at the top of your Excel screen, right-click any existing tab (like Home or Insert) and select Customize the Ribbon. In the right-hand list, check the box next to Developer and click OK.
  2. Open the Visual Basic Editor: Click the Developer tab and select the Visual Basic button on the far left, or press Alt + F11 on your keyboard. This opens the VBE window where your automation logic resides.
  3. Insert a New Module: In the VBE, go to the Insert menu and select Module. This creates a blank sheet of code where you can write your macros, keeping them separate from specific sheet or workbook objects.
  4. Write the Basic Strikethrough Macro: Copy and paste the following code into the module to apply a strikethrough to a specific cell:
    Sub ApplyStrikethrough()
            Range("B2").Font.Strikethrough = True
        End Sub
    This targets cell B2 specifically. To remove the strikethrough, you would change True to False.
  5. Create a Dynamic Range Macro: Often, you need to apply strikethroughs to whatever cells are currently selected rather than a fixed address. Use this code:
    Sub StrikeSelectedCells()
            Selection.Font.Strikethrough = True
        End Sub
    This allows you to highlight a group of cells and run the macro to mark them all at once.
  6. Implement Conditional Strikethrough: To make the process automatic (e.g., striking through a row when a status is changed to "Done"), you must use a Worksheet Event. Right-click the sheet tab at the bottom of your Excel window, select View Code, and enter the following:
    Private Sub Worksheet_Change(ByVal Target As Range)
            If Not Intersect(Target, Range("C2:C100")) Is Nothing Then
                If Target.Value = "Done" Then
                    Target.EntireRow.Font.Strikethrough = True
                Else
                    Target.EntireRow.Font.Strikethrough = False
                End If
            End If
        End Sub
    In this example, if any cell in the range C2:C100 is changed to "Done", the entire row is struck through.
  7. Apply Strikethrough to Specific Characters: If you only want to strike through a part of the text within a cell, use the Characters property. For example, to strike through the first five characters of cell A1:
    Sub StrikePartialText()
            Range("A1").Characters(Start:=1, Length:=5).Font.Strikethrough = True
        End Sub
  8. Run and Test: Return to your Excel sheet. You can run your standard macros by clicking the Macros button on the Developer tab, selecting your macro name, and clicking Run. For the Worksheet Event code, simply type "Done" into the designated column to see the effect.

Common Mistakes

One of the most frequent errors is attempting to apply the .Font.Strikethrough property to an object that does not support it. For instance, trying to apply it to a Chart object or a Shape object directly will result in a runtime error. Ensure you are targeting a Range, Cell, or Characters object.

Another common mistake is forgetting to handle the "False" state. If you write a macro that only sets the property to True, you will find yourself unable to undo the formatting via the same automation. Always build a toggle mechanism or a separate "Clear" macro to reset the formatting when data changes.

Users also frequently confuse Selection with ActiveCell. Selection refers to the entire highlighted area, while ActiveCell refers only to the single cell that has the focus. If you use ActiveCell.Font.Strikethrough = True while having ten cells highlighted, only one will be updated, which often leads users to believe the code is broken.

Finally, failing to save the workbook as an .xlsm file is a critical error. Standard .xlsx files cannot store VBA macros. If you save as .xlsx and close the file, all your strikethrough automation will be permanently deleted.

Tips

To improve performance in large spreadsheets, use Application.ScreenUpdating = False at the start of your macro and Application.ScreenUpdating = True at the end. This prevents Excel from flickering as it applies formatting to hundreds of rows, making the macro run significantly faster.

Combine strikethrough with color changes for better visibility. For example, setting the font color to a light grey (Range("A1").Font.Color = RGB(200, 200, 200)) alongside the strikethrough makes it immediately obvious that the data is no longer active.

When working with the Characters property, use the InStr function to find a specific word within a string and strike it through dynamically. This is useful for redacting specific terms or marking errors within a sentence without affecting the rest of the cell's content.

Consider using a Toggle macro. Instead of having two separate macros for "On" and "Off", use a simple logic gate: Selection.Font.Strikethrough = Not Selection.Font.Strikethrough. This flips the current state of the strikethrough, acting like a light switch.

Troubleshooting

If the code does not execute, first check if macros are enabled. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and ensure that macros are enabled or that you have clicked "Enable Content" in the yellow security warning bar at the top of the sheet.

If you receive a "Runtime Error 1004", it usually means the sheet is protected. VBA cannot change the formatting of a cell in a protected worksheet unless the protection is turned off first. You can add ActiveSheet.Unprotect "YourPassword" at the beginning of your code and ActiveSheet.Protect "YourPassword" at the end.

If the Worksheet_Change event is not firing, you may have accidentally disabled events. This happens if a previous macro crashed while Application.EnableEvents was set to False. To fix this, press Ctrl+G in the VBE to open the Immediate Window, type Application.EnableEvents = True, and press Enter.

If the strikethrough appears but the text is illegible, check if you have Conditional Formatting rules applied to the same cells. Conditional Formatting takes precedence over VBA formatting. If a rule is forcing a specific style, the VBA strikethrough may be overridden or visually clashed.

Frequently Asked Questions

Can I use a formula to apply strikethrough?

No, Excel formulas can only return values; they cannot change the formatting of a cell. You must use either Conditional Formatting or VBA to apply a strikethrough based on a cell value.

Does this work on Excel for the Web?

No, VBA macros do not run in the web version of Excel. You would need to use Office Scripts (TypeScript) to achieve similar automation in the browser.

How do I strike through only one word in a cell?

Use the Characters property. You specify the starting position of the word and the length of the word to target only that specific segment of the text string.

Will this slow down my workbook?

Applying formatting to a few cells is instantaneous. However, running a loop that checks thousands of rows every time a cell changes can cause lag. Use specific ranges instead of EntireRow to maintain speed.

Can I apply strikethrough to a whole column?

Yes, you can use Columns("A:A").Font.Strikethrough = True, but be cautious as this will apply the formatting to every single cell in that column, including empty ones, which can increase file size.