How to count Option button clicks on same userform?

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Please can someone help me?

I have a userform called OPTIONS.

I have 6 different options on the userform.

What I would like is if an operator selects an option it counts the number of times that selection has been selected in a textbox on the same userform.

For example:

If OptionButtonADD is selected then an 1 appears in TextBoxADD and if it is selected again then a 2 appears in the relevant textbox and so on.

Once I get the first code for the ADD I will be able to do the rest.

I would like a reset count code as well please to reset all the textboxes.

Any help would much appreciated.

Thanks

Dan
 
That's true.

You said:
or close the worksheet

I think you wanted to save close the
WorkBook

 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0
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
 
Upvote 0
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 [COLOR=#ff0000]myCount[/COLOR] 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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,712
Messages
6,174,031
Members
452,542
Latest member
Bricklin

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
Back
Top