ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Hi,
The cells in my sheet are all yellow,apart from the active row which is blue interior color index 8
Because of the code below D21 never changes blue at Row 21
Please could you advise how i can add .Interior.ColorIndex = 8 to the existing code so when the code is executed at cell D21 it also changes it blue to match the rest in that row.
I have the code in use below.
The cells in my sheet are all yellow,apart from the active row which is blue interior color index 8
Because of the code below D21 never changes blue at Row 21
Please could you advise how i can add .Interior.ColorIndex = 8 to the existing code so when the code is executed at cell D21 it also changes it blue to match the rest in that row.
I have the code in use below.
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 = "G"
' *** Specify start row ***
myStartRow = 21
' 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
Select Case Mid(Range("A21").Value, 10, 1)
Case Is = "X"
Range("D21").Value = "1999"
Case Is = "Y"
Range("D21").Value = "2000"
Case Is = "1"
Range("D21").Value = "2001"
Case Is = "2"
Range("D21").Value = "2002"
Case Is = "3"
Range("D21").Value = "2003"
Case Is = "4"
Range("D21").Value = "2004"
Case Is = "5"
Range("D21").Value = "2005"
Case Is = "6"
Range("D21").Value = "2006"
Case Is = "7"
Range("D21").Value = "2007"
Case Is = "8"
Range("D21").Value = "2008"
Case Is = "9"
Range("D21").Value = "2009"
Case Is = "A"
Range("D21").Value = "2010"
Case Is = "B"
Range("D21").Value = "2011"
Case Is = "C"
Range("D21").Value = "2012"
Case Is = "D"
Range("D21").Value = "2013"
Case Is = "E"
Range("D21").Value = "2014"
Case Is = "F"
Range("D21").Value = "2015"
Case Is = "G"
Range("D21").Value = "2016"
Case Is = "H"
Range("D21").Value = "2017"
Case Is = "J"
Range("D21").Value = "2018"
Case Is = "K"
Range("D21").Value = "2019"
End Select
End Sub