Add checkboxes based on table column

I had this question after viewing Checkbox - copy row to sheet.

My question is how to add checkboxes based on all value in table column with only one click on the button. below code only add one checkbox. thank you for help.

Sub NewCheckbox()
Dim lRow As Long
Dim target As Range
Dim obj As Object
'Adds a Forms toolbar checkbox to the cell
'Checkbox value is linked to that same cell, using a white font color
    
With Worksheets("Input")
    lRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row       'find  first empty row in database
    Set target = .Cells(lRow, 1)
    With .CheckBoxes.Add(target.Left, target.Top + 1, target.Width, target.Height - 1)
            .Caption = "Fakturer"
            .LinkedCell = target.Address
            .Name = "cb_" & target.Address(False, False)     'Name it like "cb_A11"
            .OnAction = "CheckboxClicked"
    End With
    target.Font.ColorIndex = 2     'White font color for linked cell TRUE/FALSE value
    target.Value = False
End With
End Sub

Open in new window

LadydeeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Can you please post a sample that shows where you want to add the checkboxes?
0
Roy CoxGroup Finance ManagerCommented:
I would use Marlett or Wingding Fonts to achieve the effect of CheckBoxes, see this example
NotCheckBoxes.xlsm
0
LadydeeAuthor Commented:
below is the example where I want to add the checkboxes. with only one button click, i want checkboxes added to all row based on table row.

Capture.PNG
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Martin LissOlder than dirtCommented:
Sub NewCheckbox()
Dim lRow As Long
Dim target As Range
Dim obj As Object
'Adds a Forms toolbar checkbox to the cell
'Checkbox value is linked to that same cell, using a white font color
    
With Worksheets("Input")
    For lRow = .ListObjects(1).DataBodyRange.Row To .ListObjects(1).DataBodyRange.Rows.Count + _
                                                    .ListObjects(1).DataBodyRange.Row - 1
        Set target = .Cells(lRow, 1)
        With .CheckBoxes.Add(target.Left, target.Top + 1, target.Width, target.Height - 1)
                .Caption = "Fakturer"
                .LinkedCell = target.Address
                .Name = "cb_" & target.Address(False, False)     'Name it like "cb_A11"
                .OnAction = "CheckboxClicked"
        End With
        target.Font.ColorIndex = 2     'White font color for linked cell TRUE/FALSE value
        target.Value = False
    Next
End With
End Sub

Open in new window

0
Martin LissOlder than dirtCommented:
If you know the name of your name (for example MyTable), then this would be better.
Sub NewCheckbox()
Dim lRow As Long
Dim target As Range
Dim obj As Object
'Adds a Forms toolbar checkbox to the cell
'Checkbox value is linked to that same cell, using a white font color
    
With Worksheets("Input")
    For lRow = .ListObjects("MyTable").DataBodyRange.Row To .ListObjects("MyTable").DataBodyRange.Rows.Count + _
                                                    .ListObjects("MyTable").DataBodyRange.Row - 1
        Set target = .Cells(lRow, 1)
        With .CheckBoxes.Add(target.Left, target.Top + 1, target.Width, target.Height - 1)
                .Caption = "Fakturer"
                .LinkedCell = target.Address
                .Name = "cb_" & target.Address(False, False)     'Name it like "cb_A11"
                .OnAction = "CheckboxClicked"
        End With
        target.Font.ColorIndex = 2     'White font color for linked cell TRUE/FALSE value
        target.Value = False
    Next
End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LadydeeAuthor Commented:
how about i want to use it for all table in multiple worksheet?
0
Martin LissOlder than dirtCommented:
I believe I've answered the question you asked, so please close this question and ask a new question.
0
Roy CoxGroup Finance ManagerCommented:
With VBA you would need to run the code everytime a new row is added. With my suggestion the "checkboc2 would be automatic.
0
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2016
1
Roy CoxGroup Finance ManagerCommented:
Pleased to help
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.