Code to loop through multiple checkboxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 30 check boxes on a spreadsheet I want to copy the values over to a
table to keep the history of the check box values each time the survey is
completed.

How can I Create a loop that retrives the value from each check box then
copies the value to the first blank row in my table. then changes the values
to all the checkboxes to false.

Thanks for any help
 
Forms or controltoolbox checkboxes ?

Are the names something like CheckBox1....CheckBox30
 
Hi Ram

I think I will use a linkedcell (see properties of each checkbox)
Use cells in a row below your data.
You can hide that row

Then you can use code from this page to copy for example A50:AD50 to the database sheet
http://www.rondebruin.nl/copy1.htm

This two examples change the values to false

Sub Test1()
For Each obj In ActiveSheet.OLEObjects
If TypeOf obj.Object Is MSForms.CheckBox Then
obj.Object.Value = False
End If
Next
End Sub

Or this one

Sub Test2()
For i = 1 To 30
ActiveSheet.OLEObjects("CheckBox" & i). _
Object.Value = False
Next
End Sub
 
Thanks for your help Ron


Ron de Bruin said:
Hi Ram

I think I will use a linkedcell (see properties of each checkbox)
Use cells in a row below your data.
You can hide that row

Then you can use code from this page to copy for example A50:AD50 to the database sheet
http://www.rondebruin.nl/copy1.htm

This two examples change the values to false

Sub Test1()
For Each obj In ActiveSheet.OLEObjects
If TypeOf obj.Object Is MSForms.CheckBox Then
obj.Object.Value = False
End If
Next
End Sub

Or this one

Sub Test2()
For i = 1 To 30
ActiveSheet.OLEObjects("CheckBox" & i). _
Object.Value = False
Next
End Sub
 
When I try to change the check box value i recieve the the following error
message
unable to get the oleobjects property of the worksheet class

Thanks for any help
 
I deleted the first checkbox so it couldn't find check box 1. I changed the
code, now it runs fine.

Thanks again
 
Note that Test1 loop through all checkboxes
So if the 30 checkboxes are the only checkboxes on the sheet use this example

No problem when you rename the checkboxes
 

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

Similar Threads

Looping through checkboxes 5
Looping through checkboxes 1
Checkbox values 2
Error '1004' 4
CheckBox to tick other CheckBoxes 5
Loop through checkboxes 7
loop help 6
vba code to access checkboxes within groups? 1

Back
Top