Need VBA code to clear userform (reset check box values to false)

flower3954

Board Regular
Joined
May 5, 2012
Messages
50
Need some assistance...

I have an excel sheet that uses a userform for data input...including check boxes.

I would like the user to be able to use a CLEAR BUTTON to reset the sheet. (including changing all the check box values back to False in userforms).

"Unload Me" of course works if the button is in the userform. But my Clear button is outside the userform. (userformincome)

I appreciate the help.

Steven
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
It is possible to call the UserForm’s public subroutine from the outside.
Put this code in the UserForm1 with 2 checkboxes:
Rich (BB code):
' Code in UserForm1
Public Sub Reset()
  Me.CheckBox1 = False
  Me.CheckBox2 = False
End Sub


The below code goes to the Module1:
Rich (BB code):
'Code in Module1
 
Sub ShowForm()
  UserForm1.Show vbModeless
End Sub
 
Sub CallTheReset()
  Call UserForm1.Reset
End Sub

Run ShowForm, change status of checkbox(es) and run CallTheReset.
Note: in the code change the names of userform and its controls as required
 
Last edited:
Upvote 0
flower3954;3712389But my Clear button is outside the userform. (userformincome) [/QUOTE said:
Why? Wouldn't it be more logical to have it on the UserForm so if the user made a mistake or whatever, he/she could simply start again by clicking the button? Also, what happens if the user clicks the clear button when the UserForm is not displayed?
 
Upvote 0
USERFORMINCOME.Controls("CheckBoxWAGEEARNER").Value = False

This did the trick.

You just need one for each checkbox.
 
Upvote 0
Modification of Reset subroutine in userform for resetting of all checkboxes to False
Rich (BB code):
' Code in UserForm1
Public Sub Reset()
  Dim x As Control
  For Each x In Me.Controls
     If TypeOf x Is MSForms.CheckBox Then x.Value = False
  Next
End Sub
 
Upvote 0
Modification of Reset subroutine in userform for resetting of all checkboxes to False
Rich (BB code):
' Code in UserForm1
Public Sub Reset()
  Dim x As Control
  For Each x In Me.Controls
     If TypeOf x Is MSForms.CheckBox Then x.Value = False
  Next
End Sub

I've placed this code in the userform and assigned it to a command button, but for some reason I have to click the button twice for it to work. The first click clears a couple of checkboxes, and the second click clears the rest. I thought maybe another macro was interfering so I did enableevents=false, but the issue persisted. Might it have to do with where the focus is set?

Apologies if commenting on this old thread is a breach of etiquette; I have the same need as the OP so I thought an additional thread would be redundant.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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