Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Change the color of a cell when I type a certain word.

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Change the color of a cell when I type a certain word.

Gord and Gary,

Thank you both for the fast answers.
This weekend I'm going to experiment with the codes.

Rickie


"Gord Dibben" <gorddibbATshawDOTca schreef in bericht
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I change the color/type of the borders I put on cells? Tourkow Excel Discussion (Misc queries) 8 November 25th 09 04:42 PM
EXCEL:HOW DO I CHANGE COLOR IN CELL BY TYPING IN ANOTHER WORD? PRECIOUS Excel Worksheet Functions 2 April 20th 09 07:42 PM
Trying to change the background of a cell if I type a certain word T-DOGG01 New Users to Excel 1 May 25th 08 10:30 PM
Trying to change the background of a cell if I type a certain word T-DOGG01 Excel Discussion (Misc queries) 2 May 25th 08 10:06 PM
macro -find all occurences of a word-change color of cell of all Lost in Alabama Excel Programming 2 January 17th 06 01:46 PM


All times are GMT +1. The time now is 07:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"