+ Reply to Thread
Results 1 to 7 of 7

Remember last selection?

  1. #1
    Alen32
    Guest

    Remember last selection?

    I have this code where user choose one of nine option button. I want my
    program to remember last selection.
    here is code:
    Private Sub CommandButton1_Click()

    Worksheets("Ark1").Activate
    Range("A1").Select

    With UserForm1
    If .OptionButton1 Then sOne = "1"
    If .OptionButton2 Then sOne = "2"
    If .OptionButton3 Then sOne = "3"
    If .OptionButton4 Then sTwo = "1"
    If .OptionButton5 Then sTwo = "2"
    If .OptionButton6 Then sTwo = "3"
    If .OptionButton7 Then sThree = "1"
    If .OptionButton8 Then sThree = "2"
    If .OptionButton9 Then sThree = "3"

    End With
    With ActiveCell
    Offset(0, 0).Value = sOne
    Offset(1, 0).Value = sTwo
    Offset(2, 0).Value = sThree


    End With
    End Sub


  2. #2
    º¼ÖÝÈË
    Guest

    Re: Remember last selection?

    public Variant



  3. #3
    Alen32
    Guest

    Re: Remember last selection?

    please more help where should i put public variant


  4. #4
    Jim Rech
    Guest

    Re: Remember last selection?

    Since you've written the option button values to a sheet you just need to
    set those option buttons from those values in the userform's Initialize
    event.

    Also, it's not necessary (or user friendly) to change selected cell in a
    workbook just to write values to the sheet. See the following:

    Private Sub CommandButton1_Click()
    With UserForm1
    If .OptionButton1 Then sOne = 1
    If .OptionButton2 Then sOne = 2
    If .OptionButton3 Then sOne = 3
    If .OptionButton4 Then sTwo = 1
    If .OptionButton5 Then sTwo = 2
    If .OptionButton6 Then sTwo = 3
    If .OptionButton7 Then sThree = 1
    If .OptionButton8 Then sThree = 2
    If .OptionButton9 Then sThree = 3
    End With
    With Worksheets("Ark1").Range("A1")
    .Offset(0).Value = sOne
    .Offset(1).Value = sTwo
    .Offset(2).Value = sThree
    End With
    End Sub

    --
    Jim
    "Alen32" <[email protected]> wrote in message
    news:[email protected]...
    > please more help where should i put public variant
    >




  5. #5
    Alen32
    Guest

    Re: Remember last selection?

    I want when I start my userform next time like I made selection last time.
    that means if I choosed optionbutton3 last time so when I start userform
    next time so optionbutton is set to true.


  6. #6
    Bob Phillips
    Guest

    Re: Remember last selection?

    Reverse the code

    Private Sub Userform_Initialize()
    With Worksheets("Ark1").Range("A1")
    sOne. = Offset(0).Value
    sTwo = .Offset(1).Value
    sThree = .Offset(2).Value
    End With

    With UserForm1
    If sOne =1 Then
    .OptionButton1.Value = True
    ElseIf sOne = 2 Then
    .OptionButton2.Value = True
    Else
    .OptionButton3.Value = True
    End If
    If sTwo=1 Then
    .OptionButton4.Value = True
    ElseIf sTwo= 2 Then
    .OptionButton5.Value = True
    Else
    .OptionButton6.Value = True
    End If
    If sThree =1 Then
    .OptionButton7.Value = True
    ElseIf sThree = 2 Then
    .OptionButton8.Value = True
    Else
    .OptionButton9.Value = True
    End If


    End With
    End Sub



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Jim Rech" <[email protected]> wrote in message
    news:[email protected]...
    > Since you've written the option button values to a sheet you just need to
    > set those option buttons from those values in the userform's Initialize
    > event.
    >
    > Also, it's not necessary (or user friendly) to change selected cell in a
    > workbook just to write values to the sheet. See the following:
    >
    > Private Sub CommandButton1_Click()
    > With UserForm1
    > If .OptionButton1 Then sOne = 1
    > If .OptionButton2 Then sOne = 2
    > If .OptionButton3 Then sOne = 3
    > If .OptionButton4 Then sTwo = 1
    > If .OptionButton5 Then sTwo = 2
    > If .OptionButton6 Then sTwo = 3
    > If .OptionButton7 Then sThree = 1
    > If .OptionButton8 Then sThree = 2
    > If .OptionButton9 Then sThree = 3
    > End With
    > With Worksheets("Ark1").Range("A1")
    > .Offset(0).Value = sOne
    > .Offset(1).Value = sTwo
    > .Offset(2).Value = sThree
    > End With
    > End Sub
    >
    > --
    > Jim
    > "Alen32" <[email protected]> wrote in message
    > news:[email protected]...
    > > please more help where should i put public variant
    > >

    >
    >




  7. #7
    Alen32
    Guest

    Re: Remember last selection?

    It works!!!
    Thanks Bob!!!


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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