View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Change the color of a cell when I type a certain word.

Here is some worksheet code you can experiment with:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
codes = Array("MED", "JAK", "KOF", "NID", "DOK", "WIK")
valuess = Array(6, 4, 41, 3, 38, 39)
v = t.Value
For i = 0 To 5
If v = codes(i) Then
Application.EnableEvents = False
t.Interior.ColorIndex = valuess(i)
Application.EnableEvents = True
Exit Sub
End If
Next
End Sub



Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu2007d


"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