Label Change Color When Text in cell is "true" on userform

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
207
i have this kind of Code in vba on my userform

Code:
Sub resetLabels()
If Sheets("Cup 128").Range("E5").Value <> False Then Label1.Caption = Sheets("Cup 128").Range("E5").Value
End Sub

this part works fine But when i try to put the Code Below into my code then the label get Red
when Start userform and no data in Cell ("D5")

I have try to get this code into it for change the Color if ("D5") have the right Text ("Text")

Code:
If Sheets("Cup 128").Range("D5").Text = "True" Then
        Me.Label1.BackColor = vbRed
        End If

but it aint work
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
as the way you descripe for mee at the 2 first line of you small change to change i my Code

so now it look's like this

Code:
Sub resetLabels()   With Sheets("Cup 128")
      For i = Rw To Rw + 29 Step 4
         J = J + 1
         If .Range("E" & i).Value <> False Then Me.Controls("Label" & J).Caption = .Range("E" & i).Value
         If .Range("E" & i + 1).Value <> False Then Me.Controls("Label" & J + 1).Caption = .Range("E" & i + 1).Value
         Me.Controls("Label" & J).BackColor = IIf(.Range("D" & i).Value, vbRed, vbWhite)
         Me.Controls("Label" & J + 1).BackColor = IIf(.Range("D" & i + 1).Value, vbRed, vbWhite)
         J = J + 1
      Next i
      For i = Rw + 2 To Rw + 27 Step 8
         J = J + 1
         Me.Controls("Label" & J).Caption = IIf(.Range("I" & i).Value = False, "", .Range("I" & i).Value)
         Me.Controls("Label" & J + 1).Caption = IIf(.Range("I" & i + 1).Value = False, "", .Range("I" & i + 1).Value)
         Me.Controls("Label" & J).BackColor = IIf(.Range("H" & i).Value, vbRed, vbWhite)
         Me.Controls("Label" & J + 1).BackColor = IIf(.Range("H" & i + 1).Value, vbRed, vbWhite)
         J = J + 1
      Next i
      For i = Rw + 6 To Rw + 23 Step 16
         J = J + 1
         Me.Controls("Label" & J).Caption = IIf(.Range("I" & i).Value = False, "", .Range("I" & i).Value)
         Me.Controls("Label" & J + 1).Caption = IIf(.Range("I" & i + 1).Value = False, "", .Range("I" & i + 1).Value)
         Me.Controls("Label" & J).BackColor = IIf(.Range("L" & i).Value, vbRed, vbWhite)
         Me.Controls("Label" & J + 1).BackColor = IIf(.Range("L" & i + 1).Value, vbRed, vbWhite)
         J = J + 1
      Next i
   End With
End Sub

i find it i didn change the Importen Part in the code

Code:
Me.Controls("Label" & J).Caption = IIf(.Range("[COLOR=#ff0000]I[/COLOR]" & i).Value = False, "", .Range("[COLOR=#ff0000]I[/COLOR]" & i).Value)
         Me.Controls("Label" & J + 1).Caption = IIf(.Range("[COLOR=#ff0000]I[/COLOR]" & i + 1).Value = False, "", .Range("[COLOR=#ff0000]I[/COLOR]" & i + 1).Value)
         Me.Controls("Label" & J).BackColor = IIf(.Range("L" & i).Value, vbRed, vbWhite)
         Me.Controls("Label" & J + 1).BackColor = IIf(.Range("L" & i + 1).Value, vbRed, vbWhite)
         J = J + 1
to M i did that and it works
 
Last edited:
Upvote 0
Glad you figured it out & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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