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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,214,838
Messages
6,121,885
Members
449,057
Latest member
Moo4247

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