Change Text Color Before a Hyphen in Excel Cells
Question details
The user needs to apply a specific font color (red) only to the characters preceding a hyphen within a cell, while keeping the rest of the text black.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Formatting text data in a column where a hyphen separates a prefix from the remaining content.
- Observed behavior
- Excel does not natively support applying multiple font colors within a single cell using standard formulas or conditional formatting.
Before proceeding, ensure that your data is stored as plain text, because partial cell formatting cannot be applied to cells containing active formulas.
Use a VBA Macro for Bulk Partial Formatting
The most efficient method for applying partial text colors across a large dataset or an entire column.
Because Excel formulas and conditional formatting rules apply to the entire cell, they cannot change the color of just a portion of the text. To automate changing the color before a hyphen across multiple cells, you must use a VBA macro.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.
Click on 'Insert' in the top menu and select 'Module' to create a blank script window.
Paste a VBA script that loops through your selected cells, uses the InStr function to find the position of the hyphen, and applies the color index (e.g., Red) to the Characters object before that position.
Close the VBA editor. Highlight the cells you want to format in your worksheet, press Alt + F8, select your macro, and click 'Run'.

Manually Change Font Color in the Formula Bar
Best for a small number of cells where you can quickly edit the text format by hand without writing code.
Try WPS Office for Your Spreadsheet Needs
If you are looking for a powerful, lightweight, and free alternative to Microsoft Office, WPS Office offers excellent compatibility with Excel formats and handles complex data processing smoothly.

Frequently Asked Questions
Can I use Conditional Formatting to change part of the text color?
No, Excel's Conditional Formatting applies styles to the entire cell. To format only a portion of the text within a cell, you must use manual formatting or a VBA macro.
Why does my partial text formatting disappear?
If the cell contains a formula, the formatting will reset to the default style whenever the formula recalculates. You must convert the formula to plain text (Copy > Paste Special > Values) before applying partial font colors.
Can I color text after the hyphen instead?
Yes. If formatting manually, simply highlight the text after the hyphen. If using VBA, modify the script to target the characters starting from the hyphen's position to the end of the text string.
Is it possible to achieve this in Google Sheets?
Like Excel, Google Sheets does not support partial cell formatting via standard formulas. You would need to format the text manually or use Google Apps Script for automation.




