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?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,851
Members
449,194
Latest member
HellScout

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