LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Worksheet Change event on different ranges with data validation

I'm trying to color code cells based on the value of a drop down
list. I want to use a worksheet change event since I have more than
three response options. Trouble is I have more than one response
pattern so I want the change event to be conditional to the cell
range. I have a range for each response pattern and corresponding
color coding scheme as below. Thanks in advance!



Private Sub Worksheet_Change(ByVal Target As Range)

Dim vLetter As String
Dim vColor As Long
Dim v2Letter As String
Dim v2Color As String
Dim v3Letter As String
Dim v3Color As String

Dim cRange As Range
Dim cell As Range
Dim c2Range As Range
Dim c3Range As Range

Set cRange = Intersect(Range("D3:J17"), Range(Target(1).Address))
If cRange Is Nothing Then Exit Sub

For Each cell In Target
vLetter = UCase(Left(cell.Value & " ", 2))
vColor = 0
Select Case vLetter
Case "YE"
vColor = 4
Case "NO"
vColor = 3
Case "CO"
vColor = 4
Case "MO"
vColor = 6
Case "PA"
vColor = 45
Case "N/"
vColor = 2

End Select
Application.EnableEvents = False
cell.Interior.ColorIndex = vColor
Application.EnableEvents = True
Next cell
'Target.Offset(0, 1).Interior.colorindex = vColor


Set c2Range = Intersect(Range("D4,D16,E10"), Range(Target
(1).Address))
If c2Range Is Nothing Then Exit Sub
For Each cell In Target
v2Letter = Left(cell.Value & " ", 5)
v2Color = 0
Select Case v2Letter
Case "Month"
v2Color = 4

Case "Quart"
v2Color = 6

Case "Never"
v2Color = 3

Case "Biann"
v2Color = 6

Case "Annua"
v2Color = 45

Case "N/A"
v2Color = 2


End Select
Application.EnableEvents = False
cell.Interior.ColorIndex = v2Color
Application.EnableEvents = True
Next cell
'Target.Offset(0, 1).Interior.colorindex = vColor

Set c3Range = Intersect(Range("F7:J7"), Range(Target(1).Address))
If c3Range Is Nothing Then Exit Sub

For Each cell In Target
v3Letter = Left(cell.Value & " ", 3)

v3Color = 0
Select Case v3Letter

Case "abc"
v3Color = 6

Case "def"
v3Color = 3


Case "jkl"
v3Color = 45

Case "mno"
v3Color = 2

End Select
Application.EnableEvents = False
cell.Interior.ColorIndex = v3Color
Application.EnableEvents = True
Next cell

End Sub
 
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
Validation Procedure with a worksheet change event Bhupinder Rayat Excel Worksheet Functions 2 October 3rd 07 05:18 PM
Worksheet change event for data validation?? Meltad Excel Programming 5 August 1st 06 03:56 PM
Worksheet Change Event With Validation List Kris_Wright_77 Excel Programming 5 January 24th 06 05:41 PM
Data Validation Listbox and the Worksheet Change Event RASENT Excel Programming 0 June 17th 05 09:26 PM
Change event for data validation listbox Steve Parkinson Excel Programming 4 January 14th 05 02:57 PM


All times are GMT +1. The time now is 08:30 AM.

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

About Us

"It's about Microsoft Excel"