PC Review


Reply
Thread Tools Rate Thread

Change the color of a cell when I type a certain word.

 
 
Rickie Gibson
Guest
Posts: n/a
 
      21st Feb 2008
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 With Quote
 
 
 
 
Gord Dibben
Guest
Posts: n/a
 
      21st Feb 2008
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")) <---------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" <(E-Mail Removed)>
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 With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      21st Feb 2008
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
>
>

 
Reply With Quote
 
Rickie Gibson
Guest
Posts: n/a
 
      21st Feb 2008
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
news:(E-Mail Removed)...
> 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")) <---------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"
> <(E-Mail Removed)>
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change cell color after processes - type mismatch Bailey Microsoft Excel Programming 1 3rd Feb 2010 08:44 PM
EXCEL:HOW DO I CHANGE COLOR IN CELL BY TYPING IN ANOTHER WORD? PRECIOUS Microsoft Excel Worksheet Functions 2 20th Apr 2009 07:42 PM
Trying to change the background of a cell if I type a certain word T-DOGG01 Microsoft Excel New Users 1 25th May 2008 10:30 PM
Trying to change the background of a cell if I type a certain word T-DOGG01 Microsoft Excel Misc 1 25th May 2008 10:06 PM
macro -find all occurences of a word-change color of cell of all =?Utf-8?B?TG9zdCBpbiBBbGFiYW1h?= Microsoft Excel Programming 2 17th Jan 2006 01:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:39 PM.