Colour Confusion

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code that manipulates the appearance of a label in my user form.

Code:
           With .Controls(hfg & "_en")
                .BorderColor = RGB(51, 204, 51)
                .BorderStyle = 1
                .ForeColor = RGB(51, 204, 51)
            End With

The RGB is a shade of green, and the label's border and font colour are given this value. All appears normal.

I am trying to use the font colour in an evaluation, ie if the font is green (RGB 51, 204, 51) then ...

Code:
With userfom1
    If  .Controls(hfg & "_en").ForeColor = RGB(51, 204, 51) Then
         .Controls(hfg & "_en").ForeColor = RGB(0, 0, 0)
    End if

I am unable to the criteria of the if statement. I had previously assigned the forecolor to that RGB value, it hasn't changed, so I would expect the value of the forecolor to be RGB 51, 204, 51 as assigned.

In the immediates pane, if I type ?.Controls(hfg & "_en").ForeColor a value of 3394611 is returned. I'm not sure how to convert that to RBG, but I suspect my codes is failing because maybe 3394611 isn't the same as RGB 51,204,51?

Is anyone able to offer a solution?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
If I set a labels font in the initialize & then check it on a command button it works for me.
Is your code checking the correct label?
 
Upvote 0
Hi Fluff ... leave it to you to help identify an easy solution (and the errors of course).
Thank you!! That was my oversight.
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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