amended code and another method of addin checkboxes with link to row
Option Explicit
Sub CopyRows()
Dim chkbx As CheckBox
Dim r As Integer
Dim lcol As Long
lcol = Cells(1, Columns.Count).End(xlToLeft).Column
'Go through each check box in active sheet
For Each chkbx In ActiveSheet.CheckBoxes
'If check box is enabled
If chkbx.Value = 1 Then
'Go through each row in the used range
For r = 1 To ActiveSheet.UsedRange.Rows.Count
'Check if checkbox is on the same row
If Cells(r, 1).Top = chkbx.Top Then
Cells(r, 2).Resize(, lcol).Copy Destination:=Worksheets("City").Range("a" & Rows.Count).End(xlUp)(2)
Exit For
End If
Next r
End If
Next
End Sub
Public Sub chbox_forRows()
Dim Frow As Variant: Dim Lrow As Variant
Dim i As Long
Dim str As String
str = InputBox("Enter first and Last row separated by -")
Frow = InStr(str, "-")
Frow = Left(str, Frow - 1)
Lrow = Right(str, Len(str) - InStr(str, "-"))
'MsgBox "Add checkboxes from row " & Frow & " to " & Lrow
For i = Frow To Lrow
XAddCheckBoxes Cell:=Range("a" & i)
Next
End Sub
Private Sub XAddCheckBoxes(Cell As Range)
With ActiveSheet.CheckBoxes.Add(Cell.Left, _
Cell.Top, _
Cell.Width, _
Cell.Height)
.LinkedCell = Cell.Offset(, 0).Address
.Caption = Range(.LinkedCell).Row
End With
End Sub
Bookmarks