LostOracle
New Member
- Joined
- Jul 17, 2018
- Messages
- 3
Hi All
I'm not sure this is possible but I came across some VBA code that allowed you to add check boxes to an active sheet based on the selection made, unfortunately the check box name remains the default "Check Box #" convention, I have successfully modified the code to add the correct prefix.
I have a need to name each check box on the first row selection as cbx_1_1, cbx_1_2, cbx_1_3, the second row would then be cbx_2_1, cbx_2_2, cbx_2_3 and so on.
I can get each check box named with the prefix cbx_ and get each entry to iterate across columns but I am struggling to have each new row iterate by 1 to get the desired format stated above.
Would appreciate some guidance and your comments are welcomed.
I'm not sure this is possible but I came across some VBA code that allowed you to add check boxes to an active sheet based on the selection made, unfortunately the check box name remains the default "Check Box #" convention, I have successfully modified the code to add the correct prefix.
I have a need to name each check box on the first row selection as cbx_1_1, cbx_1_2, cbx_1_3, the second row would then be cbx_2_1, cbx_2_2, cbx_2_3 and so on.
Code:
Sub insertCheckboxes()
Dim Rng As Range
Dim WorkRng As Range
Dim Ws As Worksheet
Dim iRowFirst As Long
Dim iColCount As Integer
Dim RowCount As Integer
iColCount = 1
On Error Resume Next
xTitleId = "Insert Check Boxes"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set Ws = Application.ActiveSheet
iRowFirst = WorkRng.Row
Application.ScreenUpdating = False
For Each Rng In WorkRng
With Ws.CheckBoxes.Add(Rng.Left, Rng.Top, Rng.Width, Rng.Height)
.Characters.Text = Rng.Value
.Name = "cbx_" & iRowFirst & "_" & iColCount
End With
iColCount = iColCount + 1
iRowFirst = iRowFirst + 1
Next
WorkRng.ClearContents
WorkRng.Select
Application.ScreenUpdating = True
End Sub
I can get each check box named with the prefix cbx_ and get each entry to iterate across columns but I am struggling to have each new row iterate by 1 to get the desired format stated above.
Would appreciate some guidance and your comments are welcomed.