We help IT Professionals succeed at work.

Add checkboxes based on table column

400 Views
Last Modified: 2018-01-17
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

Comment
Watch Question

Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Can you please post a sample that shows where you want to add the checkboxes?
Roy CoxGroup Finance Manager
CERTIFIED EXPERT

Commented:
I would use Marlett or Wingding Fonts to achieve the effect of CheckBoxes, see this example
NotCheckBoxes.xlsm

Author

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
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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

Protect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
how about i want to use it for all table in multiple worksheet?
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I believe I've answered the question you asked, so please close this question and ask a new question.
Roy CoxGroup Finance Manager
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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
Roy CoxGroup Finance Manager
CERTIFIED EXPERT

Commented:
Pleased to help

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions