Change Color of Character within Result of Formula

dwhitey1124

New Member
Joined
Oct 24, 2014
Messages
28
Hi everyone,
I would like to change the color of all underscores ("_") that are in the output of a formula. Right now I have the code for changing the color in constant cells but can't figure it out for cells that have formulas. Any advice would be much appreciated.


HTML:
Dim rng As Range
    Dim byt As Byte
       For Each rng In Range("A1:r2000").Cells.SpecialCells( _
            xlCellTypeConstants, _
            xlTextValues)
            
            For byt = 1 To Len(rng.Value)
                If Mid$(rng.Value, byt, 1) = Chr(95) Then
                    rng.Characters(byt, 1).Font.Color = _
                        rng.Interior.Color
                End If
            Next byt
        Next rng
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi everyone,
I would like to change the color of all underscores ("_") that are in the output of a formula. Right now I have the code for changing the color in constant cells but can't figure it out for cells that have formulas. Any advice would be much appreciated.


HTML:
Dim rng As Range
    Dim byt As Byte
       For Each rng In Range("A1:r2000").Cells.SpecialCells( _
            xlCellTypeConstants, _
            xlTextValues)
            
            For byt = 1 To Len(rng.Value)
                If Mid$(rng.Value, byt, 1) = Chr(95) Then
                    rng.Characters(byt, 1).Font.Color = _
                        rng.Interior.Color
                End If
            Next byt
        Next rng

Change xlCellTypeConstants to xlCellTypeFormulas.
 
Upvote 0
Hi everyone,
I would like to change the color of all underscores ("_") that are in the output of a formula.
To the best of my knowledge, you will not be able to do that. As far as I know, all the characters in the output from a formula must be formatted the same. If you get rid of the formulas and let Change event code populate your cells with text constants, then that same code can change the color of part of that text constant. Is that something you would want to pursue? If so, show us the formula you now have in the cells.
 
Upvote 0
To the best of my knowledge, you will not be able to do that. As far as I know, all the characters in the output from a formula must be formatted the same. If you get rid of the formulas and let Change event code populate your cells with text constants, then that same code can change the color of part of that text constant. Is that something you would want to pursue? If so, show us the formula you now have in the cells.
Thanks for the reminder Rick, I had forgotten that caveat when I posted my reply. :(
 
Upvote 0

Forum statistics

Threads
1,215,482
Messages
6,125,061
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top