Inserting Multiple Checkboxes

punfs

New Member
Joined
Nov 14, 2014
Messages
1
Hello all,

I am interested in creating a code that creates checkboxes in pre-selected cells, also aligning them in the center horizontally and vertically, and also offsetting the TRUE/FALSE value away from these cells
So far i have found something but it will not center the checkboxes

Any help will be greatly appreciated

Code:
Sub CellCheckbox()Dim myCell As Range, myRng As Range
Dim CBX As CheckBox


    For Each myCell In Selection
        With myCell
            Set CBX = .Parent.CheckBoxes.Add( _
                        Top:=.Top, _
                        Left:=.Left, _
                        Width:=1, _
                        Height:=1)
            CBX.Name = .Address(0, 0)
            CBX.Caption = ""
            CBX.Left = .Left + ((.Width - CBX.Width) / 2)
            CBX.Top = .Top + ((.Height - CBX.Height) / 2)
            CBX.LinkedCell = .Offset(0, 15).Address(external:=True)
            CBX.Value = xlOff
        End With
    Next myCell


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hello,

if you mean to centre the checkbox in the appropriate cell (left to right), then add +3.75 to to line beginning CBX.Left
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,337
Members
451,637
Latest member
hvp2262

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