+ Reply to Thread
Results 1 to 5 of 5

Userform Option (Radial) Button - Retain Last choice

Hybrid View

vba_madness Userform Option (Radial)... 12-11-2019, 06:43 AM
AlphaFrog Re: Userform Option (Radial)... 12-11-2019, 08:38 AM
vba_madness Re: Userform Option (Radial)... 12-11-2019, 09:27 AM
AlphaFrog Re: Userform Option (Radial)... 12-11-2019, 09:44 AM
vba_madness Re: Userform Option (Radial)... 12-11-2019, 09:59 AM
  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Userform Option (Radial) Button - Retain Last choice

    Hi there,
    I am using Option (or if you prefer, Radial) buttons within a Userform.

    To simplify the problem, let's say that there are two option buttons - Male or Female. The User selects "Male", fills out various other pieces of information and then closes down the Userform.
    The next time the User opens the Userform, I want their choice to be remembered so that "Male" is selected by default.
    Should the User change their mind at some point in the future and change the option to "Female" and then close the Userform, it will be defaulted to "Female" the next time it is opened.

    Hopefully that illustrates my objective..

    My question is, am I able to capture and alter the default choice of Options, without referencing a cell somewhere within the workbook?

    Thanks for Reading the post. Look forwards to finding out what Options are available to me!
    Attached Images Attached Images

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Userform Option (Radial) Button - Retain Last choice

    You could store the result in a Named Constant (similar to a Named Range).

    Private Sub OptionButton1_Click()
        Application.Names.Add "ufGender", "Male", False
    End Sub
    
    Private Sub OptionButton2_Click()
        Application.Names.Add "ufGender", "Female", False
    End Sub
    
    
    Private Sub UserForm_Initialize()
        If Not IsError(Evaluate("ufGender")) Then
            Select Case Evaluate("ufGender")
               Case "Male": OptionButton1.Value = True
               Case "Female": OptionButton2.Value = True
            End Select
        End If
    End Sub

    On a side note:
    I think they are colloquially referred to as Radio buttons and not Radial because they mimic the radio station push buttons on old-style radios with mechanical tuners. The radio station preset buttons would be pushed in and stay pushed in until a different preset station button was pushed. I could be very wrong on this.
    Last edited by AlphaFrog; 12-11-2019 at 09:31 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Userform Option (Radial) Button - Retain Last choice

    Hi AlphaFrog,

    Many thanks for your suggestion. I have tried that and it works a treat - Job Done!

    I had a quick look and I believe I can either use
    Evaluate("ufGender")
    or
    [ufGender]
    to retrieve the stored constant.

    Learnt a new trick - thank you!

    Can I ask a few more follow up questions regarding Named constants...
    Is the constant stored when the document is closed?
    Apart from via VBA and the Immediate Window, is there somewhere that I can see this (and potentially other Named Constants) is/are stored?
    Any warnings/caveats/restrictions that should be borne in mind when using a Named Constant?

    Is there any other way that you might go about this?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Userform Option (Radial) Button - Retain Last choice

    You're welcome.


    Quote Originally Posted by vba_madness View Post
    Is the constant stored when the document is closed?
    Yes, if the workbook is saved


    Apart from via VBA and the Immediate Window, is there somewhere that I can see this (and potentially other Named Constants) is/are stored?
    You can see them in the Name manager if you make this argument TRUE
    Application.Names.Add "ufGender", "Male", True


    Any warnings/caveats/restrictions that should be borne in mind when using a Named Constant?
    None that I can think of other than saving the workbook.


    Is there any other way that you might go about this?
    You could write the value to a text file or store the value in the user's registry.

  5. #5
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Userform Option (Radial) Button - Retain Last choice

    Thank you for the follow up answers!

    Solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 07-15-2017, 09:54 AM
  2. UserForm option button bug?
    By aarona in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2017, 04:03 AM
  3. [SOLVED] userform option button
    By adamheon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2016, 09:28 AM
  4. Checkbox radial button - very new here
    By tnursall in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2013, 01:27 AM
  5. Userform option button help
    By mecharissa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2012, 04:48 AM
  6. Replies: 2
    Last Post: 07-10-2012, 04:37 PM
  7. Userform Option Button to Show/Hide Another Option Button on same Userform
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2010, 09:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1