Barboza Babcock
New Member
- Joined
- Jul 3, 2020
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
We have adapted some vba code to programmatically populate a form with 130 option buttons. We would like to arrange the options in 4 columns, rather than having to scroll to get to the last few options.
We would also like to be able to add a label at the top of the form without it being overwritten by option buttons.
Apologizing in advance for my lack of coding skills.
Many thanks to all who take the time to look!!!
We would also like to be able to add a label at the top of the form without it being overwritten by option buttons.
Code:
Private Sub UserForm_Initialize()
Dim OptionList(1 To 130) As String, intA As Integer, strTest(1), s As Variant, i As Integer
Dim opt As Control
'Get compound list
strTest(1) = "524"
Sheets("Tests").Select
Range("A2").Select
Select Case strTest(1)
Case Is = "524"
Cells.Find(What:="524 Cpds", After:=ActiveCell, LookIn:=xlFormulas2, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
ActiveCell.Offset(rowoffset:=1).Select
intA = 1
Do Until ActiveCell = ""
OptionList(intA) = ActiveCell.Text
intA = intA + 1
ActiveCell.Offset(rowoffset:=1).Select
Loop
End Select
For Each s In OptionList
Set opt = frmCpds.Controls.Add("Forms.OptionButton.1", "radioBtn" & i, True)
opt.Caption = s
opt.Top = opt.Height * i
opt.GroupName = "Options"
opt.Width = 200
frmCpds.Width = 750
frmCpds.Height = opt.Height * (i + 2)
i = i + 1
Next
End Sub
Apologizing in advance for my lack of coding skills.
Many thanks to all who take the time to look!!!