palaeontology
Active Member
- Joined
- May 12, 2017
- Messages
- 444
- Office Version
- 2016
- Platform
- Windows
Currently I'm using the following code to highlight a selected cell ...
so, if the selected cell is (for example) G18, the highlight would look like this ...
However, I'd like to change the code a little to have the cell from row 2 (in this case cell G2) and from column A (in this case cell A18) and the selected cell (in this case G18) all to have a different fill colour (let's say some kind of light lime green).
So it might look a little like this ...
How would I have to change the code ?
Is it even possible ?
Kind regards,
Chris
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iColor As Integer
On Error Resume Next
iColor = Target.Interior.ColorIndex
If iColor < 0 Then
iColor = 36
Else
iColor = iColor + 1
End If
If iColor = Target.Font.ColorIndex Then iColor = iColor + 1
Cells.FormatConditions.Delete
With Range("A" & Target.Row, Target.Address) 'Rows(Target.Row)
.FormatConditions.Add Type:=2, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = iColor
End With
With Range(Target.Offset(1 - Target.Row, 0).Address & ":" & Target.Offset(-1, 0).Address) 'Rows(Target.Row)
.FormatConditions.Add Type:=2, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = iColor
End With
End Sub
so, if the selected cell is (for example) G18, the highlight would look like this ...
However, I'd like to change the code a little to have the cell from row 2 (in this case cell G2) and from column A (in this case cell A18) and the selected cell (in this case G18) all to have a different fill colour (let's say some kind of light lime green).
So it might look a little like this ...
How would I have to change the code ?
Is it even possible ?
Kind regards,
Chris