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!
 
so to get rid of any option boxes which are selected would it be

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

End If
Next
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
so to get rid of any option boxes which are selected would it be

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

End If
Next

or maybe i need something else ????????
 
Upvote 0
Assuming the Option Buttons are from the Forms toolbar, I believe you want:
Rich (BB code):
If TypeName(s.OLEFormat.Object) = "OptionButton" Then
 
Upvote 0
Assuming the Option Buttons are from the Forms toolbar, I believe you want:
Rich (BB code):
If TypeName(s.OLEFormat.Object) = "OptionButton" Then

Not sure how the two would go together to delete checkboxes and option buttons, which are both from the forms toolbar. Tried below but didnt workDim s As Shape For Each s In ThisWorkbook.Worksheets("Sheet1").Shapes If TypeName(s.OLEFormat.Object) = "CheckBox" Then s.OLEFormat.Object.Value = xlOff If TypeName(s.OLEFormat.Object) = "OptionButton" Then s.OLEFormat.Object.Value = xlOff End If NextRange("A2").Select End Sub
 
Upvote 0
Not sure how the two would go together to delete checkboxes and option buttons, which are both from the forms toolbar. Tried below but didnt workDim s As Shape For Each s In ThisWorkbook.Worksheets("Sheet1").Shapes If TypeName(s.OLEFormat.Object) = "CheckBox" Then s.OLEFormat.Object.Value = xlOff If TypeName(s.OLEFormat.Object) = "OptionButton" Then s.OLEFormat.Object.Value = xlOff End If NextRange("A2").Select End Sub

Its ok now, Reason it didnt work was because the check boxes were grouped and wouldnt uncheck:)

ALthough may be able to make it slightly smaller 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
If TypeName(s.OLEFormat.Object) = "OptionButton" Then
s.OLEFormat.Object.Value = xlOff
End If
Next

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingRows:=True
Range("I2").Select


<!-- / message -->
 
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.

Hi Mike,

I tried using your code in Excel 2016 but it's not working. Please help.
 
Upvote 0
Tahas, this thread is over 5 years old.
If you post a new thread describing your problem, it would get better responses. "not working" isn't very descriptive. If you explain what do you want it to do that it isn't, the responses will be better.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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