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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Alternatives are to write to a text file or the Windows registry.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,993
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:

Watch MrExcel Video

Forum statistics

Threads
1,130,309
Messages
5,641,448
Members
417,209
Latest member
Agbarker

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
Top