How to count Option button clicks on same userform?
Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: How to count Option button clicks on same userform?
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,735
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: How to count Option button clicks on same userform?

    That's true.

    You said:
    or close the worksheet

    I think you wanted to save close the
    WorkBook

    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  2. #12
    Board Regular
    Join Date
    Oct 2017
    Location
    Derby. England
    Posts
    176
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to count Option button clicks on same userform?

    Yeah sorry I meant workbook.

    Ok I'll have to go down the other route then but thank you all for all your help.

    Much appreciated.

    Regards

    Dan

  3. #13
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,735
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: How to count Option button clicks on same userform?

    You would need to put these two scripts in your Userform

    Code:
    Private Sub UserForm_Initialize()
    TextBox1.Value = Cells(1, 1).Value
    End Sub
    Private Sub UserForm_Terminate()
    Cells(1, 1).Value = TextBox1.Value
    End Sub
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  4. #14
    Board Regular
    Join Date
    Mar 2015
    Posts
    3,745
    Post Thanks / Like
    Mentioned
    66 Post(s)
    Tagged
    7 Thread(s)

    Default Re: How to count Option button clicks on same userform?

    To maintain the value whilst the workbook is open, consider using a Public variable like this

    At TOP of a standard module ABOVE all procedures
    Code:
     
    Public myCount As Long
    
    Sub DoSomething()
       xxx
    End Sub
    UserForm code
    Code:
    Private Sub OptionButtonAdd_Click()
      myCount = myCount + 1
      TextBoxADD = myCount
      OptionButtonAdd.Value = False
    End Sub
    
    Private Sub UserForm_Activate()
      TextBoxADD = myCount
    End Sub
    Last edited by Yongle; Apr 16th, 2019 at 09:03 AM.

  5. #15
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,735
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: How to count Option button clicks on same userform?

    Terminate means Unload the sheet.
    So put this code also in your Userform in case you hide the sheet and then close the workbook

    Code:
    Private Sub CommandButton1_Click()
    Cells(1, 1).Value = TextBox1.Value
    Me.Hide
    End Sub
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

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
  •