Check Boxes and Options Buttons

rhombus4

Well-known Member
Joined
May 26, 2010
Messages
586
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I've added to an existing macro so that checkboxes which have been ticked or Option buttons which have been pressed are then unticked.

I can do them individualy heres a sample

ActiveSheet.Shapes("Check Box 2103").Select
With Selection
.Value = xlOff
.LinkedCell = ""
.Display3DShading = True
End With
ActiveSheet.Shapes("Check Box 2104").Select
With Selection
.Value = xlOff
.LinkedCell = ""
.Display3DShading = True
End With

The above works fine, but I have alot of checkboxes and when I do them all the macro is very long.

I tried to record a macro (below) and do two at once which recorded fine but when I ran it I got an error " unable to set the value property of the DrawingObjects Class.

ActiveSheet.Shapes("Check Box 2103").Select
ActiveSheet.Shapes.Range(Array("Check Box 2103", "Check Box 2104")).Select
With Selection
.Value = xlOff
.LinkedCell = ""
.Display3DShading = True
End With
Range("A1").Select
End Sub

Is it possible to group them all like when you want to clear cells you can just list them in one line or range then clear contents. e.g if i had checkboxes 2101 to 2140. ALso is it possible to rename the checkbox number as alot of them are really random numbers!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
This should get you headed in the right direction:

Code:
Dim s As Shape
    For Each s In Shapes
        MsgBox s.Name & vbTab & "Shape Type: " & s.Type
    Next s
 
Upvote 0
This should get you headed in the right direction:

Code:
Dim s As Shape
    For Each s In Shapes
        MsgBox s.Name & vbTab & "Shape Type: " & s.Type
    Next s

???? Sorry im confused. DO i enter as above in my MAcro and remove everything else relating to checkboxes and option boxes
 
Upvote 0
Try:
Rich (BB code):
Sub exa2()
Dim s As Shape
    
    For Each s In ThisWorkbook.Worksheets("Sheet4").Shapes
        If TypeName(s.OLEFormat.Object) = "CheckBox" Then
            s.OLEFormat.Object.Value = xlOff
        End If
    Next
    
End Sub
 
Upvote 0
Try:
Rich (BB code):
Sub exa2()
Dim s As Shape
 
    For Each s In ThisWorkbook.Worksheets("Sheet4").Shapes
        If TypeName(s.OLEFormat.Object) = "CheckBox" Then
            s.OLEFormat.Object.Value = xlOff
        End If
    Next
 
End Sub

I already have a macro that unchecks all the checkboxes but is really long. I tried deleting everything in my macro relating to checkboxes then added the bit below but non of the checkboxes were unticked. Not sure what to add in my macro to replace my existing code.Dim s As Shape For Each s In ThisWorkbook.Worksheets("Tab1").Shapes If TypeName(s.OLEFormat.Object) = "CheckBox" Then s.OLEFormat.Object.Value = xlOff End If Next
 
Upvote 0
When posting code, please use the [code]...your code...[/code] tags.

I am not sure what the problem is. You appear to be using checkboxes from the Forms toolbar, and as long as you have the sheet's (tab) name correct, I do not see a problem.

Maybe posting the whole procedure, as you currently have it written would help to see what's going on.
 
Upvote 0
The .ControlFormat property needs to be used.
Code:
ActiveSheet.Shapes("Option Button 1").ControlFormat.Value = xlOff
 
Upvote 0
Howdy Mike,

I certainly know very little about Shapes. Is there a reason, such as version or ??? that mine worked on my end but not the OPs'? Yours certainly works, I was just curious.

Thank you so much,

Mark
 
Upvote 0
My code adresses the Shape object directly, the OP code works through Selection. I haven't figured out exactly the details, but shapes via Selection isn't the same as addressing the Shape object directly.

There is no advantage to using Selection. To the contrary.
 
Upvote 0
Howdy Mike,

I certainly know very little about Shapes. Is there a reason, such as version or ??? that mine worked on my end but not the OPs'? Yours certainly works, I was just curious.

Thank you so much,

Mark

My code adresses the Shape object directly, the OP code works through Selection. I haven't figured out exactly the details, but shapes via Selection isn't the same as addressing the Shape object directly.

There is no advantage to using Selection. To the contrary.

finally managed to get it to work thanks

added your code in the middle of my macro

Dim s As Shape
For Each s In ThisWorkbook.Worksheets("Sheet1").Shapes
If TypeName(s.OLEFormat.Object) = "CheckBox" Then
s.OLEFormat.Object.Value = xlOff

End If
Next

If i want to make sure all the option buttons are deselected as well do I just copy the above and change where it says checkbox to say option button.

Not sure about the control format as didnt understand the difference between using the forms or controlbox option
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,683
Members
452,937
Latest member
Bhg1984

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