Good morning to all,
I have conditional formatting code that works fine on its own but I have this existing code, courtesy of TMSchucks which provides a union of two existing changes. (below)
Select Case Target.Column
Case 3: Worksheet_ChangeC Target
Case 17: Worksheet_ChangeQ Target
Case Else
MsgBox "should not get here"
Exit Sub
End Select
End Sub
Private Sub Worksheet_ChangeC(ByVal Target As Range)
Dim c As Range, i As Long
On Error Resume Next
Set c = Intersect(Target, Columns(3))
If c Is Nothing Then Exit Sub
If IsEmpty(c.Offset(-1, 0)) Or Not IsEmpty(c.Offset(1, 0)) Then Exit Sub
i = c.Row
Application.EnableEvents = False
Range("A" & i - 1 & ":B" & i - 1).Copy Range("A" & i & ":B" & i)
Application.EnableEvents = True
On Error GoTo 0
End Sub
Private Sub Worksheet_ChangeQ(ByVal Target As Range)
Dim c As Range, i As Long
On Error Resume Next
Set c = Intersect(Target, Columns(17))
If c Is Nothing Then Exit Sub
If IsEmpty(c.Offset(1, 0)) Or Not IsEmpty(c.Offset(-1, 0)) Then Exit Sub
i = c.Row
Application.EnableEvents = False
Range("Q" & i - 1).Copy Range("Q" & i)
Application.EnableEvents = True
On Error GoTo 0
End Sub
The code I have for the conditional formatting is below:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("Q3:Q60000")) is Nothing Then
Select Case Target
Case 1 To 6
icolor = 4
Case 7 To 10
icolor = 45
Case 11 To 1000000000000
icolor = 3
Case Else
'Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
I can see that I could modify the existing code to suit if the conditional formatting code referred to a specific column, (I would choose case 17) but it is a range, so I am a bit stuck of how to combine it.
Any guidance much appreciated.
Thank you.
Bookmarks