Macro to clear checkboxes

G

Guy

Sorry for the duplicate posting. Previous posting was answered but solution
does not work and have had no further replies.
Is it possible to have a macro that can change all checkboxes that have been
set to checked back to ‘unchecked’?
I need a macro that will clear all of the checks in ‘checkboxes’ (forms
object) on a sheet. The checkboxes are just basic checkboxes beside peoples
names and are manually selected (checked) when that person has paid. I would
like to be able to reset all of the checkboxes back to unchecked with a macro
button. I can’t get the auto record macro function to select a forms object.
 
M

Mike H

Guy,

How you trigger the macro to do this is up to you but this uses a commnd
button on your form

Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "CheckBox" Then
cCont.Value = False
End If
Next cCont
End Sub

Mike
 
G

Guy

Hi Mike,
I am just a novice at this and I can't seem to get this to work. I think I
have figured out how to post the code to the command button I put on the
sheet but just can't get it to work. I just copied and pasted your code to
the command button screen. This is the first time I have tried to use a
command button and I am probably just making a simple mistake. Can you help?

Guy
 
M

Mike H

Guy,

I had assumed you checkboxes were on a userform, if they are on a sheet then
put a button on your sheet (You may already have done this) and assign this
code to it

Dim ws As Worksheet
Dim obj As OLEObject
Set ws = ActiveSheet
For Each obj In ws.OLEObjects
If TypeName(obj.Object) = "CheckBox" Then
obj.Object.Value = False
End If
Next obj

Mike
 
D

Dave Peterson

If those are checkboxes from the Forms toolbar:

Activesheet.checkboxes.value = xloff
 
G

Guy

Thanks to everyone,
Ya'll are great!
Special thanks to Dave, that is the simplest code I have ever used and works
great.

Thanks,
Guy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top