Excel 2003 cell background color

D

Dan E

Is there a way in Excel 2003 to have specific text content of cells set the
color of the background? e.g. all cells containing "RA" have a light green
background, "RB" have light blue.... etc., for a small set of text values.
TIA

Dan
 
G

Gord Dibben

Dan

Conditional Formatting will give you 4 formats including the default format.

Look under Format>CF and Cell Value is:


Gord Dibben Excel MVP
 
D

Dan E

Many thanks, Gord - that will give me a good start. Is there anything I
might do with a macro, that might for example examine the cell contents then
set the color depending on what it finds?

Thanks again,

Dan
 
G

Gord Dibben

Dan

Adjust text and colors to suit and just keep adding "Cases" until you're
happy.

Note: as written, will find only whole text.

e.g. "my cat eats snakes" would not be formatted.

Sub Color_Text()
Dim Cell As Range
Dim col As Integer
On Error GoTo ws_exit
For Each Cell In Selection
Select Case LCase(Cell.Value)
Case "dog": col = 1
Case "cat": col = 5
Case "snake": col = 10
Case "bird": col = 19
Case "fish": col = 20
Case Else: col = 3
End Select
Cell.Interior.ColorIndex = col
Next
ws_exit:
End Sub


Gord
 
D

Dan E

That looks pretty neat - thanks, Gord.

Dan
Gord Dibben said:
Dan

Adjust text and colors to suit and just keep adding "Cases" until you're
happy.

Note: as written, will find only whole text.

e.g. "my cat eats snakes" would not be formatted.

Sub Color_Text()
Dim Cell As Range
Dim col As Integer
On Error GoTo ws_exit
For Each Cell In Selection
Select Case LCase(Cell.Value)
Case "dog": col = 1
Case "cat": col = 5
Case "snake": col = 10
Case "bird": col = 19
Case "fish": col = 20
Case Else: col = 3
End Select
Cell.Interior.ColorIndex = col
Next
ws_exit:
End Sub


Gord
 

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