Results 1 to 6 of 6

Thread: User Form Option Button

  1. #1
    Board Regular
    Join Date
    Jun 2006
    Posts
    5,334
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default User Form Option Button

    I have a user form with several option buttons

    After selecting an option button and clicking on Ok, I would like the button to show the last option button selected


    it would be appreciated if someone could advise me how to do this

  2. #2
    Board Regular
    Join Date
    Mar 2013
    Posts
    806
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

    Default Re: User Form Option Button

    see Alex D solution to similar question posted here back in 2014

  3. #3
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: User Form Option Button

    This is one way:-
    If you add a textbox1 to your Userform it will show the previous Optionbutton as you select a new Optionbutton.
    Paste code in Userform module and add code for further option buttons as per code:-
    Code:
    Option Explicit
    Dim St1 As String, St2 As String
    Sub Lpst(op As String)
    Dim Temp As String
        If St1 = "" Then
            St1 = op
         Me.TextBox1.Text = "No Previous"
        ElseIf St2 = "" Then
            St2 = op
            Me.TextBox1.Text = St1
        Else
            Me.TextBox1.Text = St2
            St1 = St2
            St2 = op
        End If
    
    End Sub
    
    
    Private Sub OptionButton1_Change()
    Call Lpst(OptionButton1.Name)
    End Sub
    Private Sub OptionButton2_Change()
    Call Lpst(OptionButton2.Name)
    
    End Sub
    Private Sub OptionButton3_Change()
    Call Lpst(OptionButton3.Name)
    End Sub
    
    Private Sub OptionButton4_Change()
    Call Lpst(OptionButton4.Name)
    End Sub
    Regards Mick

  4. #4
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: User Form Option Button

    A similar but slightly better Option :-
    Code:
    Option Explicit
    Dim NwOp As Object
    Sub Lpst(Op As Object)
    If NwOp Is Nothing Then
        Me.TextBox1.Text = "No Previous"
        Set NwOp = Op
    Else
        Me.TextBox1.Text = NwOp.Name
        Set NwOp = Op
    End If
    End Sub
    
    Private Sub OptionButton1_Change()
     Lpst OptionButton1
    End Sub
    
    Private Sub OptionButton2_Change()
     Lpst OptionButton2
    End Sub
    
    Private Sub OptionButton3_Change()
     Lpst OptionButton3
    End Sub
    
    Private Sub OptionButton4_Change()
     Lpst OptionButton4
    End Sub
    Regards Mick

  5. #5
    Board Regular
    Join Date
    Jun 2006
    Posts
    5,334
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: User Form Option Button

    Hi Guys

    Thanks for the reply. I have used Mick's 2nd option as I found it easier to follow and adapt

    Mick, it works perfectly

  6. #6
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: User Form Option Button

    You're welcome

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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