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

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
180
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
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
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
Code:
Private Sub resetLabels()
    If Sheets("Cup 128").Range("B1") Then
        Label1.Caption = Sheets("Cup 128").Range("B1")
    End If
    If Sheets("Cup 128").Range("A1") Then
        Me.Label1.BackColor = vbRed
    End If
End Sub
 
Last edited:

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
180
Code:
[COLOR=#333333]Private Sub resetLabels()[/COLOR]    If Sheets("Cup 128").Range("B1") Then
        Label1.Caption = Sheets("Cup 128").Range("B1")
    End If
    If Sheets("Cup 128").Range("A1") Then
        Me.Label1.BackColor = vbRed
    End If [COLOR=#333333]End Sub[/COLOR]
the code you give ,Make Label Background Colored When i start Userform and Not when the Cell get the Value "True"

I Get it I get change your code with this part
Code:
[COLOR=#333333]Private Sub resetLabels()[/COLOR]    If Sheets("Cup 128").Range("B1") Then
        Label1.Caption = Sheets("Cup 128").Range("B1")
    End If
    If Sheets("Cup 128").Range("A1").Text = "TRUE" Then
        Me.Label1.BackColor = vbRed
    End If [COLOR=#333333]End Sub[/COLOR]
 
Last edited:

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Code:
[COLOR=#333333]Private Sub resetLabels()[/COLOR]    If Sheets("Cup 128").Range("B1") Then
        Label1.Caption = Sheets("Cup 128").Range("B1")
    End If
    If Sheets("Cup 128").Range("A1") Then
        Me.Label1.BackColor = vbRed
    End If [COLOR=#333333]End Sub[/COLOR]
the code you give ,Make Label Background Colored When i start Userform and Not when the Cell get the Value "True"

I Get it I get change your code with this part
Code:
[COLOR=#333333]Private Sub resetLabels()[/COLOR]    If Sheets("Cup 128").Range("B1") Then
        Label1.Caption = Sheets("Cup 128").Range("B1")
    End If
    If Sheets("Cup 128").Range("A1").Text = "TRUE" Then
        Me.Label1.BackColor = vbRed
    End If [COLOR=#333333]End Sub[/COLOR]

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    resetLabels
End Sub
Function resetLabels()
    If Sheets("Cup 128").Range("B1") Then
        UserForm1.Label1.Caption = Sheets("Cup 128").Range("B1")
    End If
    If Sheets("Cup 128").Range("A1") Then
        UserForm1.Label1.BackColor = vbRed
    End If
End Function
Paste this into your "Cup 128" code module. Change "USerform1" to whatever the name of your userform is with the label you are affecting with this code.
 
Last edited:

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
180
Sorry BUT it aint what it's should Be like

My trouble is i have this code Routine i have just only send a short Part of the Code

Code:
Private Sub UserForm_Initialize()resetLabels
End Sub




    


Sub resetLabels()
If Sheets("Cup 128").Range("E5").Value <> False Then Label1.Caption = Sheets("Cup 128").Range("E5").Value
If Sheets("Cup 128").Range("E6").Value <> False Then Label2.Caption = Sheets("Cup 128").Range("E6").Value
If Sheets("Cup 128").Range("E9").Value <> False Then Label3.Caption = Sheets("Cup 128").Range("E9").Value
If Sheets("Cup 128").Range("E10").Value <> False Then Label4.Caption = Sheets("Cup 128").Range("E10").Value
If Sheets("Cup 128").Range("E13").Value <> False Then Label5.Caption = Sheets("Cup 128").Range("E13").Value
If Sheets("Cup 128").Range("E14").Value <> False Then Label6.Caption = Sheets("Cup 128").Range("E14").Value
If Sheets("Cup 128").Range("E17").Value <> False Then Label7.Caption = Sheets("Cup 128").Range("E17").Value
If Sheets("Cup 128").Range("E18").Value <> False Then Label8.Caption = Sheets("Cup 128").Range("E18").Value
If Sheets("Cup 128").Range("E21").Value <> False Then Label9.Caption = Sheets("Cup 128").Range("E21").Value
If Sheets("Cup 128").Range("E22").Value <> False Then Label10.Caption = Sheets("Cup 128").Range("E22").Value
If Sheets("Cup 128").Range("E25").Value <> False Then Label11.Caption = Sheets("Cup 128").Range("E25").Value
If Sheets("Cup 128").Range("E26").Value <> False Then Label12.Caption = Sheets("Cup 128").Range("E26").Value
If Sheets("Cup 128").Range("E29").Value <> False Then Label13.Caption = Sheets("Cup 128").Range("E29").Value
If Sheets("Cup 128").Range("E30").Value <> False Then Label14.Caption = Sheets("Cup 128").Range("E30").Value
If Sheets("Cup 128").Range("E33").Value <> False Then Label15.Caption = Sheets("Cup 128").Range("E33").Value
If Sheets("Cup 128").Range("E34").Value <> False Then Label16.Caption = Sheets("Cup 128").Range("E34").Value
If Sheets("Cup 128").Range("I7").Value <> False Then Label17.Caption = Sheets("Cup 128").Range("I7").Value
If Sheets("Cup 128").Range("I8").Value <> False Then Label18.Caption = Sheets("Cup 128").Range("I8").Value
If Sheets("Cup 128").Range("I15").Value <> False Then Label19.Caption = Sheets("Cup 128").Range("I15").Value
If Sheets("Cup 128").Range("I16").Value <> False Then Label20.Caption = Sheets("Cup 128").Range("I16").Value
If Sheets("Cup 128").Range("I23").Value <> False Then Label21.Caption = Sheets("Cup 128").Range("I23").Value
If Sheets("Cup 128").Range("I24").Value <> False Then Label22.Caption = Sheets("Cup 128").Range("I24").Value
If Sheets("Cup 128").Range("I31").Value <> False Then Label23.Caption = Sheets("Cup 128").Range("I31").Value
If Sheets("Cup 128").Range("I32").Value <> False Then Label24.Caption = Sheets("Cup 128").Range("I32").Value
If Sheets("Cup 128").Range("M11").Value <> False Then Label25.Caption = Sheets("Cup 128").Range("M11").Value
If Sheets("Cup 128").Range("M12").Value <> False Then Label26.Caption = Sheets("Cup 128").Range("M12").Value
If Sheets("Cup 128").Range("M27").Value <> False Then Label27.Caption = Sheets("Cup 128").Range("M27").Value
If Sheets("Cup 128").Range("M28").Value <> False Then Label28.Caption = Sheets("Cup 128").Range("M28").Value
End Sub
 

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Sorry BUT it aint what it's should Be like

My trouble is i have this code Routine i have just only send a short Part of the Code

Code:
Private Sub UserForm_Initialize()resetLabels
End Sub




    


Sub resetLabels()
If Sheets("Cup 128").Range("E5").Value <> False Then Label1.Caption = Sheets("Cup 128").Range("E5").Value
If Sheets("Cup 128").Range("E6").Value <> False Then Label2.Caption = Sheets("Cup 128").Range("E6").Value
If Sheets("Cup 128").Range("E9").Value <> False Then Label3.Caption = Sheets("Cup 128").Range("E9").Value
If Sheets("Cup 128").Range("E10").Value <> False Then Label4.Caption = Sheets("Cup 128").Range("E10").Value
If Sheets("Cup 128").Range("E13").Value <> False Then Label5.Caption = Sheets("Cup 128").Range("E13").Value
If Sheets("Cup 128").Range("E14").Value <> False Then Label6.Caption = Sheets("Cup 128").Range("E14").Value
If Sheets("Cup 128").Range("E17").Value <> False Then Label7.Caption = Sheets("Cup 128").Range("E17").Value
If Sheets("Cup 128").Range("E18").Value <> False Then Label8.Caption = Sheets("Cup 128").Range("E18").Value
If Sheets("Cup 128").Range("E21").Value <> False Then Label9.Caption = Sheets("Cup 128").Range("E21").Value
If Sheets("Cup 128").Range("E22").Value <> False Then Label10.Caption = Sheets("Cup 128").Range("E22").Value
If Sheets("Cup 128").Range("E25").Value <> False Then Label11.Caption = Sheets("Cup 128").Range("E25").Value
If Sheets("Cup 128").Range("E26").Value <> False Then Label12.Caption = Sheets("Cup 128").Range("E26").Value
If Sheets("Cup 128").Range("E29").Value <> False Then Label13.Caption = Sheets("Cup 128").Range("E29").Value
If Sheets("Cup 128").Range("E30").Value <> False Then Label14.Caption = Sheets("Cup 128").Range("E30").Value
If Sheets("Cup 128").Range("E33").Value <> False Then Label15.Caption = Sheets("Cup 128").Range("E33").Value
If Sheets("Cup 128").Range("E34").Value <> False Then Label16.Caption = Sheets("Cup 128").Range("E34").Value
If Sheets("Cup 128").Range("I7").Value <> False Then Label17.Caption = Sheets("Cup 128").Range("I7").Value
If Sheets("Cup 128").Range("I8").Value <> False Then Label18.Caption = Sheets("Cup 128").Range("I8").Value
If Sheets("Cup 128").Range("I15").Value <> False Then Label19.Caption = Sheets("Cup 128").Range("I15").Value
If Sheets("Cup 128").Range("I16").Value <> False Then Label20.Caption = Sheets("Cup 128").Range("I16").Value
If Sheets("Cup 128").Range("I23").Value <> False Then Label21.Caption = Sheets("Cup 128").Range("I23").Value
If Sheets("Cup 128").Range("I24").Value <> False Then Label22.Caption = Sheets("Cup 128").Range("I24").Value
If Sheets("Cup 128").Range("I31").Value <> False Then Label23.Caption = Sheets("Cup 128").Range("I31").Value
If Sheets("Cup 128").Range("I32").Value <> False Then Label24.Caption = Sheets("Cup 128").Range("I32").Value
If Sheets("Cup 128").Range("M11").Value <> False Then Label25.Caption = Sheets("Cup 128").Range("M11").Value
If Sheets("Cup 128").Range("M12").Value <> False Then Label26.Caption = Sheets("Cup 128").Range("M12").Value
If Sheets("Cup 128").Range("M27").Value <> False Then Label27.Caption = Sheets("Cup 128").Range("M27").Value
If Sheets("Cup 128").Range("M28").Value <> False Then Label28.Caption = Sheets("Cup 128").Range("M28").Value
End Sub
Ok, then only paste this into your cup 128 module..



Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Call resetLabels
End Sub
 
Last edited:

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
180
Sorry But that Don't make sense for mee

at This Code Works as it should But I want the Labels Backgroun Change Color If each Cell For Each Line is Right

So
if D5 is true then E5 is Red Background and Not E6
if D6 is true then E6 is Red Background and Not E5
if D9 is true then E9 is Red Background and Not E10
if D10 is true then E10 is Red Background and Not E9

and so on to Last Line
If H15 is true then I15 is Red Background and Not I16
If H16 is true then I16 Is Red Background and Not I15
 

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
180
Code:
https://www.dropbox.com/s/csnipdo3tflywep/Total%20Changes.xlsm?dl=0
i have Shorten my file Down so Only the sheet's Cup 128 is there with Userforms
 

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
If your code within "resetLabels" is working "as it should" then the only thing you need to do is fire off the code anytime the sheet changes.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Call resetLabels
End Sub
That code will fire it off for you
 

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
180
HM either i aint Descripe perfectly what i want

try again Each of my Labels Works OK on my Userform

but Need Back ground Change When Cell's having the Right Worth "SAND"

i don't know if you haven't Open my file But you can See some cell's WITH Brown Color and the Word "SAND" (Danish For TRUE)

when you click on Buttons next to the "Player 1 and 2" and "Player 3 and 4"
then you can see The word "SAND change from the cell's" and it is that Function i need to be colored ON my labels as well on my sheet's
 

Watch MrExcel Video

Forum statistics

Threads
1,102,462
Messages
5,487,024
Members
407,576
Latest member
aapnarritesh

This Week's Hot Topics

Top