Checking checkboxes in a range

Peltz

Board Regular
Joined
Aug 30, 2011
Messages
87
Hi there
I manage tocheck or uncheck all checkboxes in my sheet. However, what I need to do is checking and unchecking all checkboxes in a range, eg B5:B17. Any help would be appreciated.

Thanks
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I' ve tried to bypass the problem by selecting spesific Checkboxes, but get the error: "Object variable or With Block variable not set"..

Code:
Sub Test()
Dim c As CheckBox
Dim i As Integer

For i = 1 To 18
If c.Name = ActiveSheet.CheckBoxes("Checkbox i").Name Then
        c.Value = False
End If
   
Next i
End Sub

I can't figure out whats wrong. Any input?

Thanks
 
Upvote 0
Code:
Sub MarkCheckBoxes()
Dim c As CheckBox
Dim Ws As Worksheet
Set Ws = ActiveSheet
For Each c In Ws.CheckBoxes
If c.Name = ActiveSheet.CheckBoxes("cb").Name Then
  c.Value = xlOff
  End If
Next c
End Sub

So... i tred to give the checkboxes thesame name... However it just keeps looping on the top (ist checkbox)..
 
Upvote 0
Try this:-
NB:- These are forms "Checkboxes" not "ActiveX"
Code:
[COLOR="Navy"]Sub[/COLOR] MG23Nov09
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] CheckBox
[COLOR="Navy"]Dim[/COLOR] Ws [COLOR="Navy"]As[/COLOR] Worksheet
[COLOR="Navy"]Set[/COLOR] Ws = ActiveSheet
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] c [COLOR="Navy"]In[/COLOR] Ws.CheckBoxes
 [COLOR="Navy"]If[/COLOR] Not Intersect(c.TopLeftCell, Range("B5:B17")) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
  c.Value = IIf(c =xlOn , xlOff, xlOn) '[COLOR="Green"][B][/B][/COLOR]
  [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] c

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Hi

Thanks
It doesn't quite work. What happens is that the first checkbox in the range is toggeling. The other checkboxes are not affected.
 
Last edited:
Upvote 0
They are actually "B2:B11", but I changed the range when using your code in my worksheet
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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