Young Grasshopper
Board Regular
- Joined
- Dec 9, 2022
- Messages
- 58
- Office Version
- 365
- 2016
- Platform
- Windows
Hi world!
I'm trying to write a code where the font color in row 1 and 2 changes color if any cell in the rows underneath it I selected and change back again when a cell outside of range is selected, but it don't really work..
Main problem now is that color of C:F f.ex only changes if i go outside of all three ranges, and not just when I go outside C:F.
The other problem is that this needs to be repeated for a lot more ranges; C:F, H:K, M:P, R:U, W:Z etc. (Not a problem if it's easier to do it C:G, H:I, M:Q and not skip the one column btw".
So there is probably a smarter way to write this, than writing an IF statement 100 times?
This is what i have now:
Would appreciate any help
I'm trying to write a code where the font color in row 1 and 2 changes color if any cell in the rows underneath it I selected and change back again when a cell outside of range is selected, but it don't really work..
Main problem now is that color of C:F f.ex only changes if i go outside of all three ranges, and not just when I go outside C:F.
The other problem is that this needs to be repeated for a lot more ranges; C:F, H:K, M:P, R:U, W:Z etc. (Not a problem if it's easier to do it C:G, H:I, M:Q and not skip the one column btw".
So there is probably a smarter way to write this, than writing an IF statement 100 times?
This is what i have now:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("C:F")) Is Nothing Then
Range("C1:E2").Font.Color = RGB(254, 109, 37)
Else
If Not Intersect(Target, Range("H:K")) Is Nothing Then
Range("H1:J2").Font.Color = RGB(254, 109, 37)
Else
If Not Intersect(Target, Range("M:P")) Is Nothing Then
Range("M1:P2").Font.Color = RGB(254, 109, 37)
Else
Range("B1:AA2").Font.Color = RGB(128, 128, 128)
End If
End If
End If
End If
End Sub
Would appreciate any help