Jonnyoforem
New Member
- Joined
- May 22, 2015
- Messages
- 32
I have a macro that allows me to loop through option buttons on my worksheet and then assign the name of the option button to the variable buttonName as shown in the code below.
Dim myButton As OptionButton
Dim buttonName As String
'Loop Through Option Buttons
For Each myButton In Worksheets("Search").OptionButtons
If myButton.Value = 1 Then
buttonName = myButton.Text
Exit For
End If
Next myButton
I want to do the same thing but instead of looping through option buttons on a worksheet, I have a user form with option buttons I want to loop through. It's very important that I'm able to assign a variable to whatever the name of the selected option button is because I'll be using that variable later in the code. What tweaks do i need to make to the above code to accomplish this? Thanks in advance for any help
Code:
Dim buttonName As String
'Loop Through Option Buttons
For Each myButton In Worksheets("Search").OptionButtons
If myButton.Value = 1 Then
buttonName = myButton.Text
Exit For
End If
Next myButton
Code:
I want to do the same thing but instead of looping through option buttons on a worksheet, I have a user form with option buttons I want to loop through. It's very important that I'm able to assign a variable to whatever the name of the selected option button is because I'll be using that variable later in the code. What tweaks do i need to make to the above code to accomplish this? Thanks in advance for any help