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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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:
Upvote 0
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:
Upvote 0
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:
Upvote 0
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
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
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