sir, I want to highlight excel cell by selecting different cell. for example:
highlight cell b2 when cell c2 is selected and highlight cell b2 when cell d2 is selected and highlight cell b2 when cell e2 is selected and like so on……
the following code is working for highlighting the left/right cell but I want to have a multiple conditions.
Private Sub Worksheet_SelectionChange(ByVal target As Range)
On Error Resume Next
‘Get address to reset highlighting
oldTarget = Range(“C2”)
‘Reset highlighting
Range(oldTarget).Interior.ColorIndex = xlNone
‘Highlight cell -1 columns to the right
target.Offset(0, -1).Interior.ColorIndex = 6
‘Store highlighted cell address for use next time
Range(“C2”) = target.Offset(0, -1).Address
End Sub
message edited by Azan
Private Sub Worksheet_SelectionChange(ByVal target As Range) 'Clear highlighting in B1:B27 Range("B1:B27").Interior.ColorIndex = xlNone 'Check for Selection within C1:AF27 If Not Intersect(target, Range("C1:AF27")) Is Nothing Then 'Highlight Column B in Selected row Range("B" & target.Row).Interior.ColorIndex = 6 End If End SubClick Here Before Posting Data or VBA Code —> How To Post Data or Code.