Label Change Color When Text in cell is "true" on userform
Page 1 of 6 123 ... LastLast
Results 1 to 10 of 55

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

  1. #1
    Board Regular
    Join Date
    Jun 2018
    Location
    Denmark
    Posts
    158
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

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

    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

  2. #2
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

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

    Quote Originally Posted by Hjemmet View Post
    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 by Steve_; Jul 18th, 2019 at 05:30 PM.

  3. #3
    Board Regular
    Join Date
    Jun 2018
    Location
    Denmark
    Posts
    158
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

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

    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
    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:
    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").Text = "TRUE" Then
            Me.Label1.BackColor = vbRed
        End If End Sub
    Last edited by Hjemmet; Jul 19th, 2019 at 09:29 AM.

  4. #4
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

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

    Quote Originally Posted by Hjemmet View Post
    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
    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:
    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").Text = "TRUE" Then
            Me.Label1.BackColor = vbRed
        End If End Sub

    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 by Steve_; Jul 19th, 2019 at 09:35 AM.

  5. #5
    Board Regular
    Join Date
    Jun 2018
    Location
    Denmark
    Posts
    158
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

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

    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

  6. #6
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

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

    Quote Originally Posted by Hjemmet View Post
    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 by Steve_; Jul 19th, 2019 at 10:01 AM.

  7. #7
    Board Regular
    Join Date
    Jun 2018
    Location
    Denmark
    Posts
    158
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

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

    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

  8. #8
    Board Regular
    Join Date
    Jun 2018
    Location
    Denmark
    Posts
    158
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

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

    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

  9. #9
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

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

    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

  10. #10
    Board Regular
    Join Date
    Jun 2018
    Location
    Denmark
    Posts
    158
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

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

    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •