Change cell text format based on background colour

cadewhitbourn

New Member
Joined
Oct 22, 2018
Messages
1
I would like to change the text colour used for formatting a cell based on the background colour of the current cell
i.e. I want to set the text colour to be the same as the background colour, essentially making the text in the cell invisible.

So whatever the background colour for a given range, set the text colour to be the same.

Ideally I'd like to be able to turn this macro on/off.

I am using Excel as a GANT chart and I'm maintaining a reference number in each cell that I don't want to be visible to other users, but I need to be able to easily maintain.

Any help?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
This VBA assumes that the range you select (highlight) will all have the same background color.

Code:
Option Explicit


Sub ColorMe()
    Dim c As Range, x As Long
    Set c = Selection
    x = c.Interior.ColorIndex
    c.Font.ColorIndex = x
End Sub

To revert a range selected back to black print
Code:
Option Explicit


Sub UncolorMe()
    Dim c As Range, x As Long
    Set c = Selection
    c.Font.ColorIndex = 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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