ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Afternoon,
I have a worksheet where i have certain rows a certain color.
I need to have the active cell WHITE once selected BUT when i leave the cell the cell interior color reverts back to its color BEFORE it was selected.
The below code im using does exactly that BUT in a few cells there will be the text TBA & the interior color will be RED.
I was using conditional formatting to control a cell with TBA in it to be changed RED but the code below kills it.
I then need to manually select the cell & select RED from the toolbar fill color option.
Clicking the RED cell changes it to WHITE & when i leave the cell reverts back to RED but need to then remember to apply the RED in the first place,if i explained correctly
Can you see a possible edit or workaround to get this working.
Many thanks.
I have a worksheet where i have certain rows a certain color.
I need to have the active cell WHITE once selected BUT when i leave the cell the cell interior color reverts back to its color BEFORE it was selected.
The below code im using does exactly that BUT in a few cells there will be the text TBA & the interior color will be RED.
I was using conditional formatting to control a cell with TBA in it to be changed RED but the code below kills it.
I then need to manually select the cell & select RED from the toolbar fill color option.
Clicking the RED cell changes it to WHITE & when i leave the cell reverts back to RED but need to then remember to apply the RED in the first place,if i explained correctly
Can you see a possible edit or workaround to get this working.
Many thanks.
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range) ' THIS WILL COLOUR ACTIVE CELL & KEEP INTERIOR COLOUR ONCE LEFT HAS BEEN LEFT
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 ***
myStartRow = 8
' 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))
' Check to see if cell selected is outside of range
If Intersect(Target, myRange) Is Nothing Then Exit Sub
With Target
.Worksheet.Cells.FormatConditions.Delete
.FormatConditions.Add xlExpression, , True
.FormatConditions(1).Interior.Color = vbWhite
End With
End Sub