Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worksheet_Change event won't fire to execute Macro???

A little help would be appreciated...

I have a worksheet where I am trying to color-code cells based on th
value entered into the cell. For example, if I enter the value o
"CTC" in cell E125, I would like to set the background color of th
cell to light blue. If I enter a different value of "LAT" in the sam
cell, I would like the background color to be light yellow.

Since I have about 7 different cases where I want to color cells,
can't use the conditional formatting. That being said, I believe th
best way to do this is with a Worksheet_Change event, and have create
the following and placed it in the Worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Not Intersect(Target, Range("E123:AC145")) Is Nothing Then
With Target
Select Case LCase(.Value)
Case "LAT"
.ColorInterior.ColorIndex = 36
Case "CTC"
.ColorInterior.ColorIndex = 34
Case "HOL"
.ColorInterior.ColorIndex = 44
Case "VAC"
.ColorInterior.ColorIndex = 7
Case "INFT"
.ColorInterior.ColorIndex = 11
.Font.ColorIndex = 2
Case "UNICA"
.ColorInterior.ColorIndex = 11
.Font.ColorIndex = 2
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


And it does not seem to work when I enter/change a value in one of th
cells listed in the range. I don't know if there is something else
need to do in order to enable this functionality? Can anyone help?

Thanks,

Jef

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Worksheet_Change event won't fire to execute Macro???

try this instead. You had several errors.
lcase, ColorInterior.ColorIndex = 36,etc

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:C14")) Is Nothing Then
With Target
Select Case UCase(Target)
Case "LAT"
.Interior.ColorIndex = 36
.Font.ColorIndex = xlAutomatic
Case "CTC"
..Interior.ColorIndex = 34
.Font.ColorIndex = xlAutomatic
Case "HOL"
..Interior.ColorIndex = 44
.Font.ColorIndex = xlAutomatic
Case "VAC"
..Interior.ColorIndex = 7
.Font.ColorIndex = xlAutomatic
Case "INFT"
..Interior.ColorIndex = 11
Font.ColorIndex = 2
Case "UNICA"
..Interior.ColorIndex = 11
..Font.ColorIndex = 2
Case Else
.Interior.ColorIndex = xlColorIndexNone
.Font.ColorIndex = xlAutomatic
End Select
End With
End If
End Sub

--
Don Guillett
SalesAid Software

"jpdill5 " wrote in message
...
A little help would be appreciated...

I have a worksheet where I am trying to color-code cells based on the
value entered into the cell. For example, if I enter the value of
"CTC" in cell E125, I would like to set the background color of the
cell to light blue. If I enter a different value of "LAT" in the same
cell, I would like the background color to be light yellow.

Since I have about 7 different cases where I want to color cells, I
can't use the conditional formatting. That being said, I believe the
best way to do this is with a Worksheet_Change event, and have created
the following and placed it in the Worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Not Intersect(Target, Range("E123:AC145")) Is Nothing Then
With Target
Select Case LCase(.Value)
Case "LAT"
ColorInterior.ColorIndex = 36
Case "CTC"
ColorInterior.ColorIndex = 34
Case "HOL"
ColorInterior.ColorIndex = 44
Case "VAC"
ColorInterior.ColorIndex = 7
Case "INFT"
ColorInterior.ColorIndex = 11
Font.ColorIndex = 2
Case "UNICA"
ColorInterior.ColorIndex = 11
Font.ColorIndex = 2
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


And it does not seem to work when I enter/change a value in one of the
cells listed in the range. I don't know if there is something else I
need to do in order to enable this functionality? Can anyone help?

Thanks,

Jeff


---
Message posted from
http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worksheet_Change event won't fire to execute Macro???

Don -

Thanks for the help - worked like a charm. After staring at this lon
enough, the obvious LCASE/UCASE error slipped right by me.

Jef

--
Message posted from http://www.ExcelForum.com

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
Event doesn't fire Frank Xia Excel Discussion (Misc queries) 6 February 11th 06 12:54 AM
Worksheet_Change Event Sam Excel Programming 2 November 21st 03 06:51 PM
Launch a Sub Worksheet_Change Event from inside a macro Rolo[_3_] Excel Programming 1 November 9th 03 12:02 PM
Worksheet_Change Event - Macro kills copy and paste Alan Excel Programming 5 September 23rd 03 02:58 AM
How do I get Pivot filter change event to fire? Claude Excel Programming 4 August 15th 03 10:24 PM


All times are GMT +1. The time now is 07:15 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"