+ Reply to Thread
Results 1 to 10 of 10

Commandbutton backcolor depends on caption

Hybrid View

  1. #1
    Registered User
    Join Date
    03-11-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    59

    Commandbutton backcolor depends on caption

    Hi, Everyone!

    I'm working on a seat plan project wherein if button was clicked it'll turn to green if the seat was taken however I can't seem to figure out what to do with the update that I need to do.

    Example:
    Seat 354 was reported that there was an issue with headset it should turn YELLOW IF someone pressed on the seat 354 (if it was reported previously reported that there was an issue) a Msgbox should also show the issue it has however IF it was tagged as resolved already then the button will turn green again IF pressed.

    I would really appreciate if someone will help me out.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Commandbutton backcolor depends on caption

    Private Sub CmdGroup_Click()
        Dim rngIssue As Range, strIssue As String, strResolved As String
        With CmdGroup
            If .BackColor <> &H8000000F Then
                .BackColor = &H8000000F
            Else
                Set rngIssue = Sheets("Tracker").Range("B:B").Find(.Caption, , xlValues, xlWhole, 1, 1, 0)
                If Not rngIssue Is Nothing Then
                    'There is an issue
                    strIssue = Trim(StrConv(rngIssue.Offset(, 1).Value, vbProperCase))
                    strResolved = rngIssue.Offset(, 2).Value
                    If Trim(UCase(strResolved)) = "YES" Then
                        'Issue resolved
                        .BackColor = 50000
                    Else
                        'Unresolved issue
                        Select Case strIssue
                            Case "Headset", "Mouse", "Migration Cable", "Keyboard": .BackColor = vbYellow
                            Case "Dongle", "System", "Monitor": .BackColor = vbRed
                        End Select
                        MsgBox "Issue: " & strIssue, , "Seat Issue"
                    End If
                Else
                    'No issue
                    .BackColor = 50000
                End If
            End If
        End With
        UserForm1.CountCommandButton
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-11-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    59

    Re: Commandbutton backcolor depends on caption

    Hi!
    I tried the code however it still stated the issue even though it was tagged as resolved ("YES")
    THank you for your help!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Commandbutton backcolor depends on caption

    Quote Originally Posted by serenitylai View Post
    Hi!
    I tried the code however it still stated the issue even though it was tagged as resolved ("YES")
    THank you for your help!
    It worked for me using your example workbook. Seat 151 had a resolved issue and didn't show a message.

  5. #5
    Registered User
    Join Date
    03-11-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    59

    Re: Commandbutton backcolor depends on caption

    it doesn't work on mine. Is it possible if it's due to the version of excel that I'm using?

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Commandbutton backcolor depends on caption

    It's not a version issue.

    Are you using the same example workbook that you posted?
    Did you change the code in any way?
    Did you put YES in column D; not "Y" or "Yes " ?

  7. #7
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Commandbutton backcolor depends on caption

    Private Sub CmdGroup_Click()
    Dim r As Range
    With CmdGroup
        With Sheets("Tracker")
            Set r = .Cells.Find(CmdGroup.Caption, after:=.Cells(1), LookIn:=xlValues, lookat:=xlWhole)
            If r Is Nothing Then
                If CmdGroup.BackColor = 50000 Then CmdGroup.BackColor = &H8000000F Else CmdGroup.BackColor = 50000
                UserForm1.CountCommandButton
            Else
                CmdGroup.BackColor = r.Offset(, 1).Interior.Color
                MsgBox "Issue with " & r.Offset(, 1)
            End If
        End With
    End With
    End Sub
    Private Sub CommandButton1_Click()
    Dim NextRow As Integer, ldate As String, r As Range, mycolor As Long, r2 As Range
    ldate = Format(Date, "mm/dd/yyyy")
    If TextBox1.Value <> "" Then
        With Worksheets("Tracker")
            If ComboBox2 = "NO" Then
                NextRow = Application.CountA(.Range("A:A")) + 1
                .Cells(NextRow, 1) = ldate
                .Cells(NextRow, 2) = UserForm3.TextBox1
                .Cells(NextRow, 3) = UserForm3.ComboBox1
                With .Range("I:I")
                    Set r2 = .Cells.Find(UserForm3.ComboBox1)
                    mycolor = r2.Interior.Color
                End With
                .Cells(NextRow, 3).Interior.Color = mycolor
            ElseIf ComboBox2 = "Yes" Then
                Set r = .Cells.Find(TextBox1, after:=.Cells(1), LookIn:=xlValues, lookat:=xlWhole)
                .Cells(r.Row, 2) = UserForm3.TextBox1 & "  Resolved  " & ldate
                .Cells(r.Row, 3).Interior.Pattern = xlNone
            End If
        End With
        Unload Me
    End If
    End Sub
    Kind regards
    Leo
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-22-2016
    Location
    Harare, Zimbabwe
    MS-Off Ver
    2007 & 2010
    Posts
    71

    Re: Commandbutton backcolor depends on caption

    Maybe?

    Option Explicit
    Option Compare Text
    Private Sub CmdGroup_Click()
        Dim rngIssue As Range, strIssue As String, strResolved As String
        With CmdGroup
            If .BackColor <> &H8000000F Then
                .BackColor = &H8000000F
            Else
                Set rngIssue = Sheets("Tracker").Range("B:B").Find(.Caption, , xlValues, xlWhole, 1, 1, 0)
                If Not rngIssue Is Nothing Then
                    'There is an issue
                    strIssue = Trim(StrConv(rngIssue.Offset(, 1).Value, vbProperCase))
                    strResolved = rngIssue.Offset(, 2).Value
                    If Trim(UCase(strResolved)) = "YES" Then
                        'Issue resolved
                        .BackColor = 50000
                    Else
                        'Unresolved issue
                        Select Case strIssue
                            Case "Headset", "Mouse", "Migration Cable", "Keyboard": .BackColor = vbYellow
                            Case "Dongle", "System", "Monitor": .BackColor = vbRed
                        End Select
                        MsgBox "Issue: " & strIssue, , "Seat Issue"
                    End If
                Else
                    'No issue
                    .BackColor = 50000
                End If
            End If
        End With
        UserForm1.CountCommandButton
    End Sub
    Happy? Click the * to the left.

  9. #9
    Registered User
    Join Date
    03-11-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    59

    Re: Commandbutton backcolor depends on caption

    sorry for the very late reply. Will tag this as solved. Thank you for the codes!

  10. #10
    Registered User
    Join Date
    02-22-2016
    Location
    Harare, Zimbabwe
    MS-Off Ver
    2007 & 2010
    Posts
    71

    Re: Commandbutton backcolor depends on caption

    Heelo serenitylai,

    You are welcome, glad we help solve your issue.

    Thank you for adding to my Reputation.

    Cheers.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem Backcolor Commandbutton MAC
    By pant88 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 02-10-2014, 05:18 AM
  2. [SOLVED] CommandButton caption from a different workbook
    By cboud in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-19-2014, 01:29 PM
  3. [SOLVED] CommandButton caption set on open
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 05:36 PM
  4. CommandButton Caption Text Clipped
    By ahartman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2009, 06:20 PM
  5. Commandbutton caption change
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-22-2005, 02:29 AM
  6. Commandbutton backcolor change on event
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2005, 06:15 AM
  7. Caption disappears from CommandButton.
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2005, 05:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1