Results 1 to 12 of 12

Change the Color of One Command Button with Click of Another

Threaded View

Raymundus Change the Color of One... 01-25-2016, 05:38 PM
Norie Re: Change the Color of One... 01-25-2016, 05:44 PM
Raymundus Re: Change the Color of One... 01-25-2016, 05:48 PM
Norie Re: Change the Color of One... 01-25-2016, 05:50 PM
Raymundus Re: Change the Color of One... 01-26-2016, 02:17 PM
Raymundus Re: Change the Color of One... 01-25-2016, 05:54 PM
Raymundus Re: Change the Color of One... 01-25-2016, 05:56 PM
Raymundus Re: Change the Color of One... 01-26-2016, 02:50 PM
Norie Re: Change the Color of One... 01-26-2016, 03:06 PM
Raymundus Re: Change the Color of One... 01-26-2016, 03:11 PM
Norie Re: Change the Color of One... 01-26-2016, 03:23 PM
Norie Re: Change the Color of One... 01-26-2016, 03:29 PM
  1. #1
    Registered User
    Join Date
    01-15-2016
    Location
    Dallas, TX
    MS-Off Ver
    2007
    Posts
    65

    Change the Color of One Command Button with Click of Another

    Hi All,

    Say I have 3 command buttons on a sheet (in real life I have 84). I created a class module which uses one simple sub, executing a command based on which button is clicked. Subsequently, the clicked button changes color. If you click another button, that button changes color. My challenge: when the second button is clicked, I want the first button to resume its original color.

    For Simplicity's sake, I created a workbook with 3 command buttons and applied only the code needed to change the color. Please check out the code below, and the attached workbook and see if you can come up with a solution to my challenge.

    General Module:
    Dim Buttons3() As New dButtons
    
    Private Sub Class_Init()
        Dim Sh As Worksheet
        Dim Obj As OLEObject
        Dim ButtonCount As Integer
        For Each Sh In ThisWorkbook.Worksheets
            For Each Obj In Sh.OLEObjects
                If TypeName(Obj.Object) = "CommandButton" Then
                    ButtonCount = ButtonCount + 1
                    ReDim Preserve Buttons3(1 To ButtonCount)
                    Set Buttons3(ButtonCount).ButtonGroup = Obj.Object
                End If
            Next Obj
        Next Sh
    End Sub
    Class Module:
    Public WithEvents ButtonGroup As CommandButton
    
    Private Sub ButtonGroup_Click()
    If ButtonGroup.BackColor <> RGB(225, 0, 0) Then
    ButtonGroup.BackColor = RGB(225, 0, 0)
    Else: ButtonGroup.BackColor = RGB(250, 250, 200)
    End If
    End Sub
    Thanks!
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Click oval option button to fill/unfill color, also change border color to match fill
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2015, 08:29 PM
  2. [SOLVED] click on a color button and after button click it will color entire row of cell you click
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2014, 06:06 PM
  3. [SOLVED] command button color changed while cells value change and else...
    By iqballud in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2013, 08:24 AM
  4. use a command button to click other command buttons
    By fcharl9 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2013, 08:48 PM
  5. [SOLVED] Command color change upon a click
    By macrofan2012 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-19-2012, 09:28 AM
  6. Command Button to change the subsequent rows with each click
    By sand_electro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 04:13 PM
  7. change the face color of an Excel command button
    By Chris Leah in forum Excel General
    Replies: 4
    Last Post: 07-12-2005, 10:05 AM

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