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 PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Can you please post the code that is not working & explain why?
 
Upvote 0
this is the second Resetlabels code i get from you
Code:
Sub resetLabels()   With Sheets("Cup 128")
        J = 39
      For i = 264 To 307 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 = 267 To 304 Step 8
         J = J + 1
         If .Range("I" & i).Value <> False Then Me.Controls("Label" & J).Caption = .Range("I" & i).Value
         If .Range("I" & i + 1).Value <> False Then Me.Controls("Label" & J + 1).Caption = .Range("I" & i + 1).Value
         Me.Controls("Label" & J).BackColor = IIf(.Range("H" & i).Value, vbRed, vbWhite)
         J = J + 1
      Next i
   End With
End Sub

but on my userform1 there are 16 Labels for "E" and 8 Labels for "I" and 4 Labels for "M" and 2 Labels for "R" where my Labels get there Value's
and some of the Labels Don't show anything at all
and some of the Labels Flash as they should
and My commandbuttons Works
 
Last edited:
Upvote 0
In your latest file, you have changed all the command button codes, so none of them work!
 
Upvote 0
This should do the Reset
Code:
Sub resetLabels()
   With Sheets("Cup 128")
        J = 39
      For i = 264 To 307 Step 6
         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 = 267 To 304 Step 12
         J = J + 1
         If .Range("I" & i).Value <> False Then Me.Controls("Label" & J).Caption = .Range("I" & i).Value
         If .Range("I" & i + 1).Value <> False Then Me.Controls("Label" & J + 1).Caption = .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 = 273 To 298 Step 24
         J = J + 1
         If .Range("M" & i).Value <> False Then Me.Controls("Label" & J).Caption = .Range("M" & i).Value
         If .Range("M" & i + 1).Value <> False Then Me.Controls("Label" & J + 1).Caption = .Range("M" & 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
      For i = 285 To 286 Step 2
         J = J + 1
         If .Range("R" & i).Value <> False Then Me.Controls("Label" & J).Caption = .Range("R" & i).Value
         If .Range("R" & i + 1).Value <> False Then Me.Controls("Label" & J + 1).Caption = .Range("R" & i + 1).Value
         Me.Controls("Label" & J).BackColor = IIf(.Range("Q" & i).Value, vbRed, vbWhite)
         Me.Controls("Label" & J + 1).BackColor = IIf(.Range("Q" & i + 1).Value, vbRed, vbWhite)
         J = J + 1
      Next i
   
   End With
End Sub
 
Upvote 0
Again you DID it....

Thank YOU so much for your Time to Figure IT out

it WORKS like a Shinning Diamond
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
A Single option :-)

on my userform1 after the new Code i got it works as it should be

i need a little option wher Label 70 Shows Me Who's the Winner is, it Possibel Just to Get the Winner Show in My Label70
right now my Label68 and 69 show the Player with Red Bagground as the looser of the Game

Label70 looks on Cell "R285" and "R286"
 
Last edited:
Upvote 0
You can just add a line of code into the last two commandbuttons, to change the caption of Label70
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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