WEIRD behavior w/ range.interior.color property

dhoffman

New Member
Joined
Apr 1, 2002
Messages
29
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?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I was stepping through the code I posted earlier. While stopped at a breakpoint (end sub) I put the cursor over target.interior.color and it gave the value as being 52377. Now it has just been set to 4848491, but it says it is 52377. I am not joking or crazy. But then a minute later without running the code another step, still stopped at the same breakpoint, no changes made by me whatsoever, all of a sudden the value correctly becomes 4848491. I have all of the service packs and everything installed. Is there something wrong I am doing or is there something wrong with VBA here?
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,027
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top