Sub for Creating Checkboxes

IREALLYambatman

Board Regular
Joined
Aug 31, 2016
Messages
63
Hey guys. So I've managed to modify some coding I found here to insert checkboxes into a file I'm working on. I am trying to make it into a Macro that I would call from another macro that that would place checkboxes in the center of the Range I would give it.. ie. Call CB("A1:B5") And that would place checkboxes in that whole range. I'd appreciate any help :)

Code:
Sub CB()

Dim cell, LRow As Single
Dim chkbx As CheckBox
Dim CLeft, CTop, CHeight, CWidth As Double


 


For cell = 6 To 27
        CLeft = Cells(cell, "E").Left
        CTop = Cells(cell, "E").Top
        CHeight = Cells(cell, "E").Height
        CWidth = Cells(cell, "E").Width
 
        ActiveSheet.CheckBoxes.Add(CLeft + (CWidth / 2), CTop, CWidth, CHeight).Select
        With Selection
            .Caption = ""
            .value = xlOn
            .Display3DShading = False
        End With
Next cell
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Re: Help Creating a Sub for Creating Checkboxes

Quote: "place checkboxes in the center of the Range I would give it.. ie. Call CB("A1:B5") And that would place checkboxes in that whole range"
To me, clear as mud
 
Upvote 0
Re: Help Creating a Sub for Creating Checkboxes

Hello IREALLYambatman,

Perhaps something like this...

Code:
Sub CB(ByVal Address As String)

    Dim cell As Range
    Dim chkbx As CheckBox


        For Each cell In Range(Address)
            With ActiveSheet.CheckBoxes.Add(cell.Left + (cell.Width / 2), cell.Top, cell.Width, cell.Height)
                .Caption = ""
                .Value = xlOn
                .Display3DShading = False
            End With
        Next cell


End Sub
 
Last edited:
Upvote 0
Re: Help Creating a Sub for Creating Checkboxes

Hello IREALLYambatman,

You're welcome.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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