I wanted to make the active cell on a worksheet appear as a certain color no matter the original color of the cell. So I wrote this code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub
If Not OldTarget Is Nothing Then
OldTarget.Interior.Color = OldColor
End If
OldColor = Target.Interior.Color
Set OldTarget = Target
Target.Interior.Color = 4848491
End Sub
The weird thing is that sometimes target.interior.color doesn't return the correct color value. I'm completely sure about this. I can run a routine to specifically set a cell's interior color to say 4848491, and then without doing anything check the value of the same cell's interior color and the value returned is not the same (it's always 52377). However the cell's actual color on the worksheet is correct. But when the routine above runs the actual color does become 52377. Does anybody have a clue as to what could be going on? Should I use colorindex instead?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub
If Not OldTarget Is Nothing Then
OldTarget.Interior.Color = OldColor
End If
OldColor = Target.Interior.Color
Set OldTarget = Target
Target.Interior.Color = 4848491
End Sub
The weird thing is that sometimes target.interior.color doesn't return the correct color value. I'm completely sure about this. I can run a routine to specifically set a cell's interior color to say 4848491, and then without doing anything check the value of the same cell's interior color and the value returned is not the same (it's always 52377). However the cell's actual color on the worksheet is correct. But when the routine above runs the actual color does become 52377. Does anybody have a clue as to what could be going on? Should I use colorindex instead?