ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,699
- Office Version
- 2007
- Platform
- Windows
Morning all,
Hope you had a good Christmas.
Below is a current working code which not only does it high lite the row but also the active cell.
I now have a sheet which i would like to use it on BUT i need to also high lite the column as well as the row / active cell.
The columns in question will be A:K
The high lighted colors for row / column will be the same & take on the current color in use being Interior.ColorIndex = 8
Please could you advise the additional code i need to add & please show where i need to place it.
Thanks
Hope you had a good Christmas.
Below is a current working code which not only does it high lite the row but also the active cell.
I now have a sheet which i would like to use it on BUT i need to also high lite the column as well as the row / active cell.
The columns in question will be A:K
The high lighted colors for row / column will be the same & take on the current color in use being Interior.ColorIndex = 8
Please could you advise the additional code i need to add & please show where i need to place it.
Thanks
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim myStartCol As String
Dim myEndCol As String
Dim myStartRow As Long
Dim myLastRow As Long
Dim myRange As Range
If Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
' *** Specify columns to apply this to ***
myStartCol = "A"
myEndCol = "K"
' *** Specify start row ***
If (Target.Row > 4 And Target.Row < 29) Then
myStartRow = 5
Else: myStartRow = 29
End If
' Use first column to find the last row
If (Target.Row > 4 And Target.Row < 29) Then
myLastRow = 28
Else: myLastRow = 30
End If
' Build range to apply this to
Set myRange = Range(Cells(myStartRow, myStartCol), Cells(myLastRow, myEndCol))
' Clear the color of all the cells in range
Range("A5:K30").Interior.ColorIndex = 2
' Check to see if cell selected is outside of range
If Intersect(Target, myRange) Is Nothing Then Exit Sub
' This color will Highlight the row
If (Target.Row > 4 And Target.Row < 29) Then
Range(Cells(Target.Row, myStartCol), Cells(Target.Row, myEndCol)).Interior.ColorIndex = 8
Else
Range(Cells(Target.Row, myStartCol), Cells(Target.Row, myEndCol)).Interior.ColorIndex = 3
End If
' This color will Highlight the cell in the row
If (Target.Row > 4 And Target.Row < 29) Then
Target.Interior.Color = vbGreen
Else
Target.Interior.Color = vbRed
End If
Application.ScreenUpdating = True
End Sub