ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
Morning all,
I have the below working code which highlights a certain selection of cells for easier viewing.
My request please is that i also need the same to happen but for another range in the same worksheet.
Please could you advise an edit/fix so this is possible for me.
It will be the same start row & colour index, but i need to add into the equation the extra range,
Mystartcol = Y and also BC
Myendcolumn = AH and also BY
Many Thanks
I have the below working code which highlights a certain selection of cells for easier viewing.
My request please is that i also need the same to happen but for another range in the same worksheet.
Please could you advise an edit/fix so this is possible for me.
It will be the same start row & colour index, but i need to add into the equation the extra range,
Mystartcol = Y and also BC
Myendcolumn = AH and also BY
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 = "Y"
myEndCol = "AH"
' *** Specify start row ***
myStartRow = 2
' Use first column to find the last row
myLastRow = Cells(Rows.Count, myStartCol).End(xlUp).Row
' Build range to apply this to
Set myRange = Range(Cells(myStartRow, myStartCol), Cells(myLastRow, myEndCol))
' Clear the color of all the cells in range
myRange.Interior.ColorIndex = 6
' Check to see if cell selected is outside of range
If Intersect(Target, myRange) Is Nothing Then Exit Sub
' Highlight the row and column that contain the active cell
Range(Cells(Target.Row, myStartCol), Cells(Target.Row, myEndCol)).Interior.ColorIndex = 8
Target.Interior.Color = vbGreen
Application.ScreenUpdating = True
End Sub
Many Thanks