Vba to add mulitiple checkbox in one column and select all check

przemek

New Member
Joined
Jan 6, 2015
Messages
13
I got nr of request to be action. Each request can have any nr of items, generally it's between 5-40 items per request. Column A consist name of request. I want to add in one column checkbox for each item and in next column checkbox for all items from that request. So that user can select can select any individual item or whole request.
I've managed to add checkboxes, but then hit issue with names for check boxes and can't move forward.
Code:
Sub woff_checkbox()
Dim lr As Integer
lr = Cells(Rows.Count, "A").End(xlUp).Row
For i = 4 To lr
ActiveSheet.CheckBoxes.Add(Cells(i, 7).Left, Cells(i, 7).Top, 100, 15).Select
With Selection
    .Caption = Cells(i, 1)
    .name = Cells(i, 1)
End With
Next
For i = 4 To lr
    If Cells(i, 1) = Cells(i - 1, 1) Then
        '
    Else
        ActiveSheet.CheckBoxes.Add(Cells(i, 8).Left, Cells(i, 8).Top, 100, 15).Select
        With Selection
            .Caption = "All " & Cells(i, 1)
            .name = "All " & Cells(i, 1)
        End With
    End If
Next
End Sub

On next step I wanted to assign macro to checkboxes for whole request, so once clicked each item from request will have the same value as Select All checkbox.
Code:
Sub SelectAll_Click()
Dim my_name As String
Dim cb As CheckBox
Dim cb_value As Long
my_name = Application.Caller
cb_value = ActiveSheet.Shapes(my_name).OLEFormat.Object.value
For Each cb In ActiveSheet.CheckBoxes
    If cb_value = xlOn Then
        If cb.name = Mid(my_name, 5) Then
          cb.value = xlOn
        End If
    Else
        If cb.name = Mid(my_name, 5) Then
            cb.value = xlOff
        End If
    End If
Next
End Sub

code is somehow working for first item only. most likely because names for other items don't match but it could be something else - as form controls are some new thing for me

thanks for reading and suggestion
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,196,046
Messages
6,013,069
Members
441,747
Latest member
darkman77

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