ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
Hi,
I was just looking for a basic code that when i select a cell it would turn Red.
When i leave that cell & select another it would revert back to its original colour & the new selected cell would then take on board the red colour.
What i am finding is this.
My whole sheet is yellow.
I select cell A1 & it then turns Red.
I then select cell B4.
Now cell A1 turns back to Yellow & now cell B4 is Red
So now looking at my sheet all cells are Yellow apart from the last selected cell of which in this case is B4
I save the sheet & close it.
Next time i open the sheet i see cell B4 is Red so i click in cell B22
Now i have cell B4 Red & also cell B22 Red
As i click around the code does what it should do but cell B4 is still Red.
I click cell Z1 save & close the worksheet.
Now when i open the worksheet i have cell Z1 & cell B4 Red so i start clicking around but these two cells dont change.
So every time i save & close the sheet the last selected cell will then be added each time to my growing Red cells.
Z1 B4 etc etc etc
Here is the code in use.
I was just looking for a basic code that when i select a cell it would turn Red.
When i leave that cell & select another it would revert back to its original colour & the new selected cell would then take on board the red colour.
What i am finding is this.
My whole sheet is yellow.
I select cell A1 & it then turns Red.
I then select cell B4.
Now cell A1 turns back to Yellow & now cell B4 is Red
So now looking at my sheet all cells are Yellow apart from the last selected cell of which in this case is B4
I save the sheet & close it.
Next time i open the sheet i see cell B4 is Red so i click in cell B22
Now i have cell B4 Red & also cell B22 Red
As i click around the code does what it should do but cell B4 is still Red.
I click cell Z1 save & close the worksheet.
Now when i open the worksheet i have cell Z1 & cell B4 Red so i start clicking around but these two cells dont change.
So every time i save & close the sheet the last selected cell will then be added each time to my growing Red cells.
Z1 B4 etc etc etc
Here is the code in use.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static rngPrev As Range, PrevColor As Integer
Dim TempColor As Integer
TempColor = Target.Cells(1, 1).Interior.ColorIndex
If Not rngPrev Is Nothing Then rngPrev.Interior.ColorIndex = PrevColor
PrevColor = TempColor
With Target.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Set rngPrev = Target
End Sub