View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Ardus Petus Ardus Petus is offline
external usenet poster
 
Posts: 718
Default Q: How to color a cell based on values in two cells

Sorry: I did not properly read your original posting.

Here is the code.
Whenever either col A or B changes, it applies the formatting to col A.

'------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

'Agrandir la plage verticalement selon les besoins
Dim oCell As Range

If Intersect(Target, Range("A:B")) _
Is Nothing _
Or Target.Count 1 _
Then
Exit Sub
End If

Set oCell = Cells(Target.Row, "A")
If oCell.Offset(0, 1).Value < 0.05 Then
oCell.Interior.ColorIndex = xlNone
oCell.Font.Bold = False
Else
Select Case Target.Value

Case vbNullString
oCell.Interior.ColorIndex = xlNone
oCell.Font.Bold = False

Case Is < -10
oCell.Interior.ColorIndex = 3
oCell.Font.Bold = True
oCell.Borders.ColorIndex = 1

Case -10 To -5
oCell.Interior.ColorIndex = 46
oCell.Font.Bold = True
oCell.Borders.ColorIndex = 1

Case -5 To -0.5
oCell.Interior.ColorIndex = 44
oCell.Font.Bold = True
oCell.Borders.ColorIndex = 1

Case 2 To 5
oCell.Interior.ColorIndex = 35
oCell.Font.Bold = True
oCell.Borders.ColorIndex = 1

Case 5 To 10
oCell.Interior.ColorIndex = 4
oCell.Font.Bold = True
oCell.Borders.ColorIndex = 1

Case 10 To 1000
oCell.Interior.ColorIndex = 10
oCell.Font.Bold = True
oCell.Borders.ColorIndex = 1

Case Else
oCell.Interior.ColorIndex = xlNone
oCell.Font.Bold = False

End Select
End If
End Sub
'---------------------------------------

HTH
--
AP