简体   繁体   中英

Editing multiple properties in userform

I have a userform with 25 Option Buttons (OptionButton1, OptionButton2, etc..) I want to populate the captions of each of these buttons with information from the spreadsheet. I'm not sure of the best code to get this done.

For x = 1 to 25
    OptionButton & x & .caption = range("a" & x)
Next x

Obviously that won't work but that's kind of what I want it to do. Any ideas?

You can do something like this:

Private Sub UserForm_Initialize()
    Dim x As Byte
    'change Sheet1 to suit
    With ThisWorkbook.Worksheets("Sheet1")
        For x = 1 To 25
            Me.Controls("OptionButton" & x).Caption = .Range("A" & x)
        Next x
    End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM