Formatting checkboxes in VBA

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I have the following code to insert checkboxes in my worksheet. I am trying to have them maintain the property of moving with the cells, but it doesn't seem to be applying the change because when I right click and go to the format control window / properties tab, it is always at don't move or size with cells.

VBA Code:
           ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight).Select
                With Selection
                    .Caption = ""
                    .value = xlOff
                    .LinkedCell = addMe.Offset(n, 22).Address
                    .Display3DShading = False
                    .Placement = xlMove
                    .PrintObject = True
                End With
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Looks like it works after restarting the file. Couldn't tell you why it wasn't working prior to that.
 
Upvote 0
Solution
As by default on my side when inserting a checkbox the property is already set to move no need any codeline …​
Try manually and check it out !​
 
Upvote 0
As an aside, there's no need to do any selecting. Your code can be re-written as follows...

VBA Code:
                With ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight)
                    .Caption = ""
                    .Value = xlOff
                    .LinkedCell = addMe.Offset(n, 22).Address
                    .Display3DShading = False
                    .Placement = xlMove
                    .PrintObject = True
                End With
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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