VBA & Macro Problems

How to Color Specific Text Segments in Every Row in WPS Office Excel Using VBA

Phi Hung VoPhi Hung Vo Nov 13, 2026 869 views

Question details

The user needs to apply different font colors to specific character ranges or bit segments in each row of an Excel worksheet because standard worksheet formulas cannot partially format text within a cell.

How to Color Specific Text Segments in Every Row in WPS Office Excel Using VBA
Product
WPS Office Excel
Device & OS
not provided
Scenario
A worksheet contains text or bit strings in every row, and the user wants to color selected portions of each row's text with a single command or repeatable process.
Observed behavior
Standard formulas and conditional formatting only apply whole-cell formatting; they cannot color individual characters or bit ranges inside a cell, so partial character formatting requires a VBA macro or external data formatting.
Before you start

Open the workbook in WPS Office Excel and press Alt+F11 to open the VBA editor. Save the workbook as a macro-enabled .xlsm file so the character-color macro can run.

Solution 1Recommended

Apply a VBA Macro to Color Specific Character Positions in Every Row

Use this when you need true character-level formatting across many rows and want a repeatable, single-command solution.

A VBA macro can loop through each row, read the cell value, and apply different font colors to defined character positions or text segments. This is the only way to format partial cell text from within Excel.

1
Open the VBA editor

In WPS Office Excel, press Alt+F11 to open the VBA editor, or go to Developer > Visual Basic if the Developer tab is visible.

2
Insert a module

In the VBA editor, right-click the workbook project in the Project Explorer, choose Insert > Module, and open the new module.

3
Paste and adjust the macro

Enter a macro that loops through the target rows and uses Characters(start, length).Font.Color = RGB(255,0,0) for each text segment. Change the cell range and the character start and length values to match your bit ranges or text segments.

4
Run the macro

Press F5 or click Run > Run Sub/UserForm in the VBA editor, select the macro name, and confirm that the text parts in every row receive the expected colors.

Apply a VBA Macro to Color Specific Character Positions in Every Row
Character-level color applied: After the macro runs, the selected character ranges retain their colors even if you apply other whole-cell formatting.

Color Specific Text Segments in WPS Office Excel with a VBA Macro

Use the VBA editor in WPS Office Excel to loop through rows and color only the character ranges you need. WPS Office preserves the familiar Excel VBA workflow and Microsoft Excel file compatibility, so you can run the same macro logic in .xlsm workbooks.

  1. 1. Open WPS Office Excel: Launch WPS Office Excel and open the workbook that contains the rows you want to format.
  2. 2. Open the VBA editor: Press Alt+F11 or go to Developer > Visual Basic to open the VBA editor.
  3. 3. Insert the macro: Insert a module and write a macro that loops through the target range and applies Characters(start, length).Font.Color to each selected text segment.
  4. 4. Run and save: Run the macro with F5, then save the workbook as an Excel Macro-Enabled Workbook (.xlsm) to keep the code and formatting.
Apply character-level font colors to selected bit ranges or text segments with a reusable macroKeeps full compatibility with Microsoft Excel .xlsx and .xlsm filesFamiliar Excel ribbon and VBA editor make migration from Microsoft Office easyFree, lightweight Office suite that supports macros on Windows
microsoft office alternative - wps office

Frequently Asked Questions

Can a regular Excel formula color only part of the text in a cell?

No. Worksheet formulas cannot apply partial character-level formatting. Use a VBA macro that targets Characters(start, length).Font.Color, or use conditional formatting if whole-cell color is enough.

How do I open the VBA editor in WPS Office Excel?

Press Alt+F11. If the Developer tab is enabled, you can also go to Developer > Visual Basic. You can enable the Developer tab from File > Options > Customize Ribbon.

Can conditional formatting color specific text segments inside a cell?

No. Conditional formatting evaluates whole cells and applies whole-cell formats. It cannot color individual characters, bit ranges, or text segments within a cell.

Can the VBA macro work if I open the same workbook in Microsoft Excel?

Yes. Save the workbook as a macro-enabled .xlsm file and enable macros. The character-level font color logic is compatible with Microsoft Excel because it uses the same VBA Characters property.

How can I automatically reapply the colors when cell values change?

Use a Worksheet_Change event macro in the VBA editor. In the sheet module, call the formatting macro from Worksheet_Change so it runs whenever the target cells are updated.