Highlighting part row when cell clicked on

willmac

New member
Joined
May 28, 2019
Messages
3
Reaction score
0
Points
0
Excel Version(s)
2007 .xlsm
Hi, I have found plenty of info on highlighting a row when a cell is clicked on but what I really wanted was that if a cell was clicked on in a row I only want to highlight the part of that row from column A to column G. If that's possible I only want to start from row 7 downwards as I have headers above this.
 
I've moved your thread to the VBA section, as this is a VBA question.
 
Like this?
Code goes in the sheet module.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Range("A7:G200"), Target) Is Nothing Then [COLOR=#008000]'modify range according to your needs[/COLOR]
Dim cl As Range, y As Integer, tr As Integer, mycolor As Integer
tr = Target.Row: mycolor = 8
For Each cl In Range("A7:G200") [COLOR=#008000]'modify range according to your needs[/COLOR]
If cl.Interior.ColorIndex = mycolor Then
cl.Interior.ColorIndex = -4142
End If
Next cl
For y = 1 To 7
If Cells(tr, y).Interior.ColorIndex = -4142 Then
Cells(tr, y).Interior.ColorIndex = mycolor
End If
Next y
End If
End Sub
 
Back
Top