Results 1 to 8 of 8

Thread: How to get name of Option Button created dynamically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    Following your approach, and stealing a little from Sam

    You could use a Options class With Events, but this is a little more straight forward


    Option Explicit
    
    
    Dim aryOB() As msForms.OptionButton
    Dim r As Range
    
    
    Private Sub Userform_Initialize()
        Dim t As Long           ' Top of OPtion Button
        Dim r1 As Range
        
        With Sheet8
            Set r = Range(.Range("A36"), .Range("A36").End(xlDown))
        
            ReDim aryOB(36 To 36 + r.Rows.Count - 1)
        End With
        
        t = 119                ' top of First Option Button
        
        For Each r1 In r.Cells
            Set aryOB(r1.Row) = Controls.Add("Forms.OptionButton.1")
            With aryOB(r1.Row)
               .Caption = r1.Value
               .Height = 18
               .Width = 120
               .Left = 130
               .Top = t
               .Font.Size = 12
            End With
            
            t = t + 19
       Next
    
    
    End Sub
    
    
    
    
    Private Sub CBPtoceed_Click()
        Dim i As Long
    
    
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
    
    
        For i = LBound(aryOB) To UBound(aryOB)
            If aryOB(i) Then
                MsgBox "Selected " & aryOB(i).Caption
                Exit Sub
            End If
        Next i
    
    
        MsgBox "Nothing Selected"
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •