VBA & Macro Problems

How to Delete Characters of a Specific Color Using Excel VBA Macros

Elise WilliamsElise Williams Nov 3, 2026 870 views

Question details

The user wants to remove all characters formatted with a specific font color (such as red) from selected cells in a worksheet.

How to Delete All Characters of a Specific Color with Excel VBA Macros
Product
Excel
Device & OS
not provided
Scenario
Cleaning up or formatting data in an Excel worksheet where certain individual characters within cells are marked with specific font colors and need to be removed.
Observed behavior
Characters matching the specified color need to be deleted without affecting the remaining text or causing character position index shifts during the macro execution.
Before you start

Ensure you have saved a backup copy of your Excel file, as actions performed by VBA macros typically cannot be reversed using the standard Undo feature.

Solution 1Recommended

Use a VBA Macro to Scan Cells from Right to Left

This is the most reliable method. Deleting characters starting from the end of the string prevents the remaining character positions from shifting, avoiding skipped characters.

When removing specific characters from a text string via VBA, looping forward (left to right) causes the index positions to shift every time a character is deleted. To bypass this issue, the macro should loop backward through the string's length.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in Excel.

2
Insert a New Module

In the top menu, click 'Insert' and select 'Module' to create a blank workspace for your code.

3
Write the Right-to-Left Loop

Create a macro that loops through each cell in your `Selection`. Within that loop, create a reverse step loop for the characters: `For i = Len(cell.Value) To 1 Step -1`.

4
Set the Color Condition

Inside the character loop, add an IF statement to check the font color, for example: `If cell.Characters(i, 1).Font.Color = vbRed Then cell.Characters(i, 1).Delete`.

5
Run the Macro

Close the VBA editor, highlight the target cells on your worksheet, and press ALT + F8 to select and run your new macro.

Use a VBA Macro to Scan Cells from Right to Left
Choosing the Target Range: You can modify the macro's target range to `Selection`, `ActiveSheet.UsedRange`, or `ActiveSheet.Range("A1").CurrentRegion` depending on whether you want to process specific highlighted cells, the entire used sheet, or a contiguous data block.
Process Data Effectively

Use WPS Office to Run Excel VBA Macros Smoothly

WPS Office offers comprehensive support for VBA (Visual Basic for Applications) and Excel macros, allowing you to run your scripts for deleting colored characters effortlessly. It provides a lightweight, highly compatible spreadsheet environment for all your data formatting needs.

  1. 1. Download and Install WPS Office: Get WPS Office from the official website and open your .xlsm or .xlsx file using WPS Spreadsheet.
  2. 2. Access the VBA Environment: Navigate to the Developer tab on the top ribbon and click on 'VBA Editor' to launch the coding interface.
  3. 3. Run Your Macro: Insert a new module, paste your character-deleting VBA script, and click the 'Run' button to process your data.
Fully compatible with Microsoft Excel (.xlsx, .xlsm, .xls) file formats.Built-in VBA editor to easily write, edit, and execute complex macros.Lightweight installation with rapid performance, even on large datasets.Free and intuitive interface that requires no new learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why should I scan characters from right to left when deleting them in VBA?

When you delete a character from left to right, the index positions of all subsequent characters shift to the left. By scanning from right to left, the positions of the characters yet to be checked remain unaffected, preventing skipped characters and execution errors.

What is the difference between UsedRange and CurrentRegion in VBA?

`UsedRange` encompasses all cells that have ever contained data or formatting on the worksheet. `CurrentRegion` refers specifically to a contiguous block of data bounded by empty rows and columns around a specific starting cell.

How do I find the correct VBA color code to match the font?

You can use standard VBA color constants like `vbRed` or `vbBlue`. For custom colors, use the `RGB(red, green, blue)` function in your VBA code to match the exact font color applied to your characters.

Can I undo a VBA macro after it deletes the characters?

No, actions performed by a VBA macro generally clear the Undo stack in Excel. It is highly recommended to save a copy of your workbook before running any macro that modifies or deletes data.