VBA Code to arrange 100 plus option buttons on the screen, or allow scrolling

Barboza Babcock

New Member
Joined
Jul 3, 2020
Messages
13
Office Version
  1. 365
Platform
  1. 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.

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!!!
 
PERFECT!!!!!!!!!!!!!!!!!!!!!!!!!!! Project complete. This was a weekend thrash. For over 30 years we have been generating reports in a specified form. This code, and your help have allowed us to create reports for selected compounds "on the fly".

Excellent. I can't tell you how much I appreciate your help. I have a "how to" macro in excel. All commented out. It tells me how to do a bunch of different things in excel. It's my tool chest. You have helped me to add some great new techniques to the tool chest. I'm new to the forum. Is there a way I can give you "stars".

TY,

BB
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Glad to help & thanks for the feedback.

Letting me know my idea9s0 have worked & a word of thanks are all I ask for. Which you have already done. :)
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

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