WEIRD behavior w/ range.interior.color property
Find bottlenecks in your Excel workbooks
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: WEIRD behavior w/ range.interior.color property

  1. #1
    New Member
    Join Date
    Apr 2002
    Location
    Lawrence, KS
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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?

  2. #2
    New Member
    Join Date
    Apr 2002
    Location
    Lawrence, KS
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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?

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com