View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
ShaneDevenshire ShaneDevenshire is offline
external usenet poster
 
Posts: 2,344
Default Assigning a cell colors via IF-THEN statements

Hi,

You could use VBA as follows:

Sub ColorCells()
Dim cell As Excel.Range
For Each cell In Selection
With cell.Interior
Select Case cell
Case Is < -10
.ColorIndex = 14
Case 0
.ColorIndex = 41
Case 1, 4, 6
.ColorIndex = 13
Case 7 To 20
.ColorIndex = 8
Case Else
.ColorIndex = 45
End Select
End With
Next cell
End Sub

This example shows how to use many of the Select Case options.
--
Cheers,
Shane Devenshire
Microsoft Excel MVP
Join http://setiathome.berkeley.edu/ and download a free screensaver to help
find life off planet earth.

"Gravy Man" wrote:

Hello!

Can you assign a cell a specific color using an If-Then statement...instead
of using conditional formatting?

For example, if I'm evaluating a value in cell C8, which will assign a color
to cell B8 accordingly. Is this possible?

Thank you for the help!