VBA: text same color as cell background color

K

K. Georgiadis

I'm using the following code (compliments of Otto
Moehrbach)to color cells a specific color, depending on
cell contents:
Sub ChangeColor()
Dim Cell As Range
Dim RngToCheck As Range
With Sheets("Chart")
Set RngToCheck = .Range("B9:G20", .Range
(.UsedRange.Address))
End With
For Each Cell In RngToCheck
With Sheets("Chart")
Select Case .Range(Cell.Address).Value
Case "EX"
Cell.Interior.Color = vbMagenta
Case "CS"
Cell.Interior.Color = vbGreen
Case "GE"
Cell.Interior.Color = vbRed
Case "RE"
Cell.Interior.Color = vbBlue
Case Else
Cell.Interior.Color = vbWhite
End Select
End With
Next Cell
End Sub

My question is: how can I make the font color to match
the cell background, so that the code word contained in
the cell(e.g., "GE") becomes invisible?

Also how can I adjust the code so that it accepts upper,
lower, or mixed cases (e.g., GE, Ge, ge)?

Thanks a bunch
 
D

Don Guillett

just add adding it in.
Select Case .Range(Cell.Address).Value
Case "EX"
Cell.Interior.Color = vbMagenta

cell.Font.Color = cell.Interior.Color
Don Guillett
SalesAid Software
(e-mail address removed)
 
K

K. Georgiadis

Is a separate command needed for each of the four key
words? Is it possible to add a "universal" command
whereby Cell.font.color = cell.Interior.color?
 
D

Don Guillett

Now that you bring it up, guess not.
add it after select case

end with
cell.Font.Color = cell.Interior.Color
next cell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top