Using Macros to untick checkboxes in specified ranges

csbaer

New Member
Joined
Aug 29, 2020
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hello!

I'm using the VBA code below to uncheck boxes in my worksheet, and I've assigned it to a shape so when I click it, all checkboxes are unticked.

However, since there are separate sections within the worksheet, I want separate macros that untick checkboxes in different ranges, i.e. one to untick checkboxes in column B, another for column C, etc.

Is this possible?

I
VBA Code:
Sub ClearCheckBoxes()
'Updateby Extendoffice
    Dim chkBox As Excel.CheckBox
    Application.ScreenUpdating = False
    For Each chkBox In ActiveSheet.CheckBoxes
            chkBox.Value = xlOff
    Next chkBox
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi & welcome to MrExcel.
For col B, how about
VBA Code:
Sub ClearCheckBoxes()
   Dim chkBox As Excel.CheckBox
   Application.ScreenUpdating = False
   For Each chkBox In ActiveSheet.CheckBoxes
      If chkBox.TopLeftCell.Column = 2 Then chkBox.Value = xlOff
   Next chkBox
   Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
For col B, how about
VBA Code:
Sub ClearCheckBoxes()
   Dim chkBox As Excel.CheckBox
   Application.ScreenUpdating = False
   For Each chkBox In ActiveSheet.CheckBoxes
      If chkBox.TopLeftCell.Column = 2 Then chkBox.Value = xlOff
   Next chkBox
   Application.ScreenUpdating = True
End Sub

Thank you for the welcome, and thanks so much for this! Is there also a way to specify selections within VBA? Say I want untick checkboxes within the range B2:B10?
 
Upvote 0
How about
VBA Code:
Sub ClearCheckBoxes()
   Dim chkBox As Excel.CheckBox
   Application.ScreenUpdating = False
   For Each chkBox In ActiveSheet.CheckBoxes
      If Not Intersect(chkBox.TopLeftCell, Range("B2:B10")) Is Nothing Then chkBox.Value = xlOff
   Next chkBox
   Application.ScreenUpdating = True
End Sub
 
Upvote 0
How about
VBA Code:
Sub ClearCheckBoxes()
   Dim chkBox As Excel.CheckBox
   Application.ScreenUpdating = False
   For Each chkBox In ActiveSheet.CheckBoxes
      If Not Intersect(chkBox.TopLeftCell, Range("B2:B10")) Is Nothing Then chkBox.Value = xlOff
   Next chkBox
   Application.ScreenUpdating = True
End Sub
Thanks a lot! I just used
VBA Code:
If Not chkBox.TopLeftCell.Range("B5:B18") Is Nothing Then chkBox.Value = xlOff
and it got me what I wanted :) thanks again for the help!
 
Upvote 0
You're welcome & thanks for the feedback.
The code you are using will remove the check from every checkbox, not just those in B5:B18
 
Upvote 0
You're welcome & thanks for the feedback.
The code you are using will remove the check from every checkbox, not just those in B5:B18
Oh pants, that's not what I want! Do i have to use 'intersect' to stop that from happening?
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

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