Possible to keep optionbutton's value if on form and form is closed?

supdawg

Well-known Member
Joined
Mar 18, 2007
Messages
608
I have a form which has 4 optionbuttons on it. I was wondering if it were possible for the user to select the option they want and the form close and I still be able to reference which button was selected after the form was closed/unloaded?

I've been pasting the results of the selection in a conspicuous cell and calling on that later one in the sub. I know this way is not ideal.

Is it possible to do what I desire or is my workaround the only solution?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Here's another option.
Put these subs in a normal module
Code:
Sub Set1()
    With ThisWorkbook.VBProject.vbcomponents("UserForm1")
        If Not .Designer Is Nothing Then
                .Designer.Controls("OptionButton1").Value = True
        End If
    End With
End Sub
Sub Set2()
    With ThisWorkbook.VBProject.vbcomponents("UserForm1")
        If Not .Designer Is Nothing Then
                .Designer.Controls("OptionButton2").Value = True
        End If
    End With
End Sub
Sub Set3()
    With ThisWorkbook.VBProject.vbcomponents("UserForm1")
        If Not .Designer Is Nothing Then
                .Designer.Controls("OptionButton3").Value = True
        End If
    End With
End Sub
Sub Set4()
    With ThisWorkbook.VBProject.vbcomponents("UserForm1")
        If Not .Designer Is Nothing Then
                .Designer.Controls("OptionButton4").Value = True
        End If
    End With
End Sub
and this in the userform's code module
Code:
Private Sub UserForm_Terminate()
    Dim i As Long
    For i = 1 To 4
        If Controls("OptionButton" & i).Value Then
            Application.OnTime Now, "Set" & i
        End If
    Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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