Grouping Objects

DeutchBose

Board Regular
Joined
Mar 22, 2004
Messages
83
I have several command buttons on a form, and I'm trying to program it so that when a user clicks on one of the buttons, the text on that button turns red, and all the other buttons remain blue.

Is there a way to group the buttons together, so I can easily adjust the properties of all of them...as opposed to listing each individual button each time I want to do this?
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,219
Office Version
  1. 365
Platform
  1. Windows
I don't think you can group buttons but you could cycle through all the controls and identify the buttons.

Perhaps code like this:
Code:
Private Sub Command0_Click()
    ColourButtons "Command0"
End Sub
Private Sub Command1_Click()
    ColourButtons "Command1"
End Sub
Private Sub Command2_Click()
    ColourButtons "Command2"
End Sub
Private Sub Command3_Click()
    ColourButtons "Command3"
End Sub

Sub ColourButtons(strCtl)
Dim ctl
    For Each ctl In Me.Controls
        If ctl.Name <> strCtl Then
            ctl.ForeColor = vbBlue
        Else
            ctl.ForeColor = vbRed
        End If
    Next

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,961
Messages
5,599,061
Members
414,281
Latest member
Engjamal2021

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
Top