Looping through control (ctrl) and changing color based on IF statement

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
Sheepish of putting this out but I can't really figure this out. I have a several dozen labels on a userform in which a calculated value is placed. I have an IF statement that either enters a "-" or a value based on some criteria and I'd like to turn the font color red. But I've having trouble with this supposedly easy task:

*Forgive the partial code*
Code:
dFinalScore = Format((AvgArray(1) - AvgArray(lNumSections)) / (AvgArray(lNumSections) + 0.000000000001) * 100, "0")
    If (lColNdx = 0 Or Abs(dFinalScore) < TextBox1.Value Or Abs(dFinalScore) > 1000) Then
        ctrl.Caption = "-"
    Else
        ctrl.Caption = dFinalScore & "%"
        ctrl.Caption.ForeColor = vbRed  'THIS IS THE PART THAT DOESN'T WORK
    Erase AvgArray
    lColNdx = 0
    End If
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try...

Code:
[COLOR=#333333]ctrl.ForeColor = vbRed[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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