ActiveSheet.CheckBoxes.Value = False

NX555V

Board Regular
Joined
Feb 27, 2007
Messages
159
Hello

How do I make the macro check to see if the boxes are checked/not checked before hand?

So if they are checked, then it unchecks them : if unchecked then it checks them


Also,

How would I assign a range of check boxes so that it does the above, not for all checkboxes on the sheet but for a specific range?

Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Are these ActiveX checkboxes or are they from the Forms menu?
Controls aren't in cells. Like Shapes, they're in a "layer" above the cells.
Is "upper left corner of the control above a cell in the specified range" an adiquate condition for your situation?
Or would you need "all portions of the control are above a cell in the specified range"?
 
Upvote 0
The checkboxes are form control checkboxes. The checkboxes are along S27 to X27 and another set about 15 rows below in the same columns. Thanks for your help
 
Upvote 0
When the boxes are true and false they fill out a chart. I have 19 checkboxes for individual sets of data. I want to be able to check them all on and off in one shot.

Thanks
 
Upvote 0
These subs might help
Code:
Sub allChkBoxesOn()
    Call TurnAllCheckBoxes(True)
End Sub

Sub allChkBoxesOff()
    Call TurnAllCheckBoxes(False)
End Sub

Sub SomeChkBoxesOn()
    Dim ChangeBoxesInRange As Range
    Set ChangeBoxesInRange = Range("a1:D30")
    Call TurnAllCheckBoxes(True, ChangeBoxesInRange)
End Sub

Sub SomeChkBoxesOff()
    Dim ChangeBoxesInRange As Range
    Set ChangeBoxesInRange = Range("a1:D30")
    Call TurnAllCheckBoxes(False, ChangeBoxesInRange)
End Sub

Sub TurnAllCheckBoxes(newValue As Boolean, Optional withinRange As Range)
    Dim oneShape As Object
    Dim newFormsValue As Long
    If withinRange Is Nothing Then Set withinRange = ActiveSheet.Cells
    newFormsValue = IIf(newValue, xlOn, xlOff)
    With withinRange.Parent
        For Each oneShape In .Shapes
            With oneShape
                If (Not Application.Intersect(.TopLeftCell, withinRange) Is Nothing) _
                    And (Not Application.Intersect(.BottomRightCell, withinRange) Is Nothing) Then
                If .Type = msoFormControl Then
                    If .FormControlType = xlCheckBox Then
                        .OLEFormat.Object.Value = newFormsValue
                    End If
                End If
                End If
            End With
        Next oneShape
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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