
Originally Posted by
Leith Ross
When you need exclusive selection, one out of many, the control of choice is a Radio Button. Trying to alter the inherent functionality of a control when you don't need to is not a good use of your time, unless you just want to know how it is done.
Yes. OptionButtons (RadioButtons) (I'm talking the Form type, not the ActiveX type) will work as a group if enclosed in a GroupBox. Enclosing the OptionButtons in a GroupBox can be fraught as it seems that the GroupBox should completely enclose the OptionButtons - but I've found that still isn't always the case! Anyway here's a bit of code to add some OptionButtons, and a few (invisible) enclosing GroupBoxes on the active sheet:
Sub blah()
With ActiveSheet
Set rngChkBoxes = .Range("I5,I7,I9,I18") 'only the first cell of each pair
'Delete ALL existing Form groupboxes and Form optionbuttons on the sheet:
For Each c In .OptionButtons
c.Delete
Next
For Each c In .GroupBoxes
c.Delete
Next
For Each cll In rngChkBoxes.Cells
Set cll2 = cll.Offset(, 1) 'the second optionbutton location
With .OptionButtons.Add(cll.Left, cll.Top, cll.Width, cll.Height)
.Caption = ""
.Height = cll.Height 'needed because it doesn't take on the correct height
End With
With .OptionButtons.Add(cll2.Left, cll2.Top, cll2.Width, cll2.Height)
.Caption = ""
.Height = cll2.Height 'needed because it doesn't take on the correct height
'.LinkedCell = cll.Offset(, -1).Address(external:=True) 'this will also be the linked cell for all the option buttons in the same group.
End With
Set myRng = .Range(cll, cll2)
With .GroupBoxes.Add(myRng.Left, myRng.Top, myRng.Width, myRng.Height)
'.Caption = ""
.Height = myRng.Height 'needed because it doesn't take on the correct height
.Visible = False
End With
Next cll
End With
End Sub