View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Change the color of a cell when I type a certain word.

Do you need it in VBA?

Conditional Formatting will give you same function.

If in VBA, event code behind the sheet would do.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Range
Set vRngInput = Intersect(Target, Range("D:D")) <---------change to suit
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case UCase(rng.Value)
Case Is = "A": Num = 10 'green
Case Is = "B": Num = 1 'black
Case Is = "C": Num = 5 'blue
Case Is = "D": Num = 7 'magenta
Case Is = "E": Num = 46 'orange
Case Is = "F": Num = 3 'red
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

Edit the A, B, C etc. to suit.


Gord Dibben MS Excel MVP
On Thu, 21 Feb 2008 21:44:08 +0100, "Rickie Gibson"
wrote:

I'm using Excel 2003.
To do some planning and I'm using 6 different codes, for instance MED, JAK,
KOF, NID, DOK, WIK.
For each code I have defined a different color, for instance the code JAK
gets the color red. The other codes have different colors.

So, what I want to happen is that, when for instance I type JAK in cel F8
(or any other cel in the excel-sheet), this cel F8 must get automatically
get the color red.

How can I do this?
I'm not a programmer, but I really need this.
Can somebody provide me with an example how to program this in VB?


Rickie