Enabling Option Buttons by groupname

Longwalker

New Member
Joined
Oct 31, 2007
Messages
34
Hi All
As a first-time participant I hope someone may be able to help me

On a vba form in excel, I have created 20 groups of 8 option buttons each with a unique groupname
I want to enable or disable option buttons by groupname according to some parameters
Can someone please tell me what he code line is to do this?

Many thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
This will do it:

Code:
Private Sub CommandButton1_Click()

    Dim Item As MSForms.Control
    
    For Each Item In Me.Controls
    
        If TypeName(Item) = "OptionButton" Then
        
            If Item.GroupName = "group1" Then
            
                If Item.Enabled = True Then
                
                    Item.Enabled = False
                    
                Else
                
                    Item.Enabled = True
                    
                End If
                
            End If
            
        End If
        
    Next Item
    

End Sub

However, you may wish to consider grouping the controls in frames. When you change the Enable property of a frame, the controls contained within it behae as if their Enabled property has also been changed (if you check their Enabled property with Code, it will be unchanged, but the effect to the user is the same as if that property has changed). This method would be much easier... plus you get to provide a visual cue to teh user that certain optiobuttons are grouped, by virtue of the frame border. If you didn't WANT the frame border to appear, you can also change the appearance so it's effectively invisible.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

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