View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.newusers
Ranger888 Ranger888 is offline
external usenet poster
 
Posts: 2
Default how to change a cell color based on its content using macro?

Hi Bob,
Thanks for taking time to reply, your solution is perfect.
Regards,
Rod

"Bob Phillips" wrote:


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1" '<=== 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 "red": .Interior.ColorIndex = 3 'red
Case "yellow": .Interior.ColorIndex = 6 'yellow
Case "blue": .Interior.ColorIndex = 5 'blue
Case "green": .Interior.ColorIndex = 10 'green
End Select
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)



"Ranger888" wrote in message
...
Hi, I want to automatically change the color of a cell when a user select
a
color from a drop-down list. For example: user selects 'green' would
change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks