View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Changing cell text color based on cell number

maybe you want

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 20: .Interior.ColorIndex = 3 'red
Case 20.1: .Interior.ColorIndex = 5 'blue
etc.
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

or maybe even

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Int(.Value) < .Value Then
.Interior.Colorindex = 5
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"scotty" wrote in message
...
I have one column of 50 rows in which I put input Whole numbers. In cell
A1
I may input 20. When I input that I may want the text color red or I may
want
it to be blue. How can I dictate what color is used with out having to
change the color manually. I was working along the lines of if I enter 20
it
is blue and If I enter 20.1 is red and format the cells so they dislay
zero
decimal points. I have not been able to figure this out. Help is
Appreciated