Userform Option Button Captions

dkindred

New Member
Joined
Sep 6, 2010
Messages
9
how do i call the caption for the option button that called the Macro?

in my mind this what should work (but doesnt ;)) -

Code:
Sub macro1()
Sheets("Sheet1").Range("a1") = UserForm1.Frame1.Controls(Application.Caller).Caption
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
On a Userform. you could use ActiveControl. Since your control is in a frame,

Code:
Function RealActiveControl() as Object
    Set RealActiveControl = Userform1.ActiveControl
    Do While True
      Select Case TypeName(RealActiveControl)
          Case "Frame"
              Set RealActiveControl = RealActiveControl.ActiveControl
          Case "MultiPage"
              With RealActiveControl
                  Set RealActiveControl = .Pages(.Value).ActiveControl
              End With
          Case Else
              Exit Function
      End Select
    Loop
End Function
Then RealActiveControl.Caption will return the caption you seek.
 
Upvote 0
Mike,

thanks for the reply. I have no clue how to use that code :confused: sorry.

is it not possible to use and application caller for this?

Code:
Sheets("Sheet1").Range("a1") = UserForm1.optionbutton1.Caption

the code above works for one optionbutton, but i dont want seperate code for each option button in my userform.
 
Upvote 0
You could pass the caption when calling Macro1

Code:
Private Sub OptionButton1_Click()
    Macro1 OptionButton1.Caption
End Sub

Private Sub OptionButton2_Click()
    Macro1 OptionButton2.Caption
End Sub

Sub Macro1(strCapt As String)
    Sheets("Sheet1").Range("A1") = strCapt
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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