I have a piece of code that only works when there are many check boxes. However when I only have one checkbox the code bugs. Basically what I want the macro to do is to select the ckeckbox as an object and align it to a cell it should also work if more than one checkbox. Could you please help? Many thanks in advance. Please see code attached
Worksheets("Analysis Line Cupboards by Pick").CheckBoxes.Select
Selection.ShapeRange.Align msoAlignCenters, msoFalse
Selection.ShapeRange.IncrementLeft 45
Range("A10000").Select
You can align a checkbox (or any shape) on another shape, or on a cell with the left property.
Example, for an ActiveX checkbox in a Sheet to be aligned on cell B5:
In your case (adapt it):
Or, if you have multiple checkboxes, give them appropriate names and loop through them. For example, their names could be chbx_A, chbx_Hello, chbx_10 or something.
This verifies that the shape's name starts with chbx to avoid moving other shapes. You can use this to differentiate certain groups of checkboxes, as well!
For a NON-ActiveX checkbox, use the following syntax to refer to it's left, for example:
For it's value:
For
.Top
it works the same way. The.Left
and.Top
properties are numeric values measured in pixels. If you want to go to an absolute position, you can writeSheets("Sheet1").OLEObjects("chbx_A").Left = 150
for example. When you are making the shape's Left = to the cell's left, the code actually goes to see what Absolute value the left position of the cell is, and gives it to that shape. If I can elaborate, you could write: