Hi all,
After doing a search and reading through all of the posts on workarounds for applying more than 3 conditional formats, I still can't get a working solution to my application. There must be something simple I'm missing, but I can't figure it out.
My workbook contains two sheets, the first sheet accommodates pasted data from an outside app. The second sheet grabs data from the first and lays it out to match an Avery label format (30 labels...3 across and 10 down) for printing. Each label area is made up of a range of 9 cells, for example, the first label will print out the data contained in cells A1:C3. There is a column and a row separating each label, so the next label to the right is made up data shown in cells E1:G3, etc.
The traditional conditional formatting for each label cell range is based on the day of the week listed in the right-most upper cell of each label range, so for the first label (cells A1:c3), the 3 conditional format formulas for all 9 cells are:
1. =weekday(C1)=2, then font color = red
2. =weekday(C1)=3, then font color = blue
3. =weekday(C1)=4, then font color = green
I need two more conditional formats for Thursday and Friday. Granted, I could always have the default color be for one of these, but I'm still short one conditional format. I tried converting some of the existing VBA code out there to accommodate for this, but could not get it to work. I seem to be having problems applying the code to all 30 cell ranges:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A1:C3"))
If vRngInput Is Nothing Then Exit Sub
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = Weekday(C1) = 2: Num = 3 'red
Case Weekday(C1) = 3: Num = 5 'blue
Case Weekday(C1) = 4: Num = 10 'green
Case Weekday(C1) = 5: Num = 7 'magenta
Case Weekday(C1) = 6: Num = 1 'black
End Select
'Apply the color
rng.Font.ColorIndex = Num
Next rng
Set vRngInput = Intersect(Target, Range("E1:G3"))
If vRngInput Is Nothing Then Exit Sub
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = Weekday(G1) = 2: Num = 3 'red
Case Weekday(G1) = 3: Num = 5 'blue
Case Weekday(G1) = 4: Num = 10 'green
Case Weekday(G1) = 5: Num = 7 'magenta
Case Weekday(G1) = 6: Num = 1 'black
End Select
'Apply the color
rng.Font.ColorIndex = Num
Next rng
Set vRngInput = Intersect(Target, Range("I1:K3"))
If vRngInput Is Nothing Then Exit Sub
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = Weekday(K1) = 2: Num = 3 'red
Case Weekday(K1) = 3: Num = 5 'blue
Case Weekday(K1) = 4: Num = 10 'green
Case Weekday(K1) = 5: Num = 7 'magenta
Case Weekday(K1) = 6: Num = 1 'black
End Select
'Apply the color
rng.Font.ColorIndex = Num
Next rng
Set vRngInput = Intersect(Target, Range("A5:C7"))
If vRngInput Is Nothing Then Exit Sub
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = Weekday(C5) = 2: Num = 3 'red
Case Weekday(C5) = 3: Num = 5 'blue
Case Weekday(C5) = 4: Num = 10 'green
Case Weekday(C5) = 5: Num = 7 'magenta
Case Weekday(C5) = 6: Num = 1 'black
End Select
'Apply the color
rng.Font.ColorIndex = Num
Next rng
...I keep going untill I have all 30 label ranges layed out but it's not working right. What can I do to get this to work?
Thanks!
Bookmarks