Consulting

Results 1 to 6 of 6

Thread: copy rows with checkbox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    copy rows with checkbox

    when I press a button my table has to be expanded with 1 row. but also a checkbox has to be copied and its code behind it. How do I do this because it doesn't work this way? the line in bold is the error.

    Private Sub CommandButton2_Click()
        Dim lastRow As Long
        Dim lastColumn As Long
        Dim chkBox As CheckBox
        'Determine the last row in the active worksheet
        lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        'Determine the last column you want to expand
        lastColumn = 7
        'Insert a row above the last row
        Rows(lastRow + 1).Insert
        'Copy the formulas from the last row to the new row
        Range(Cells(lastRow, 1), Cells(lastRow, lastColumn)).Copy Range(Cells(lastRow + 1, 1), Cells(lastRow + 1, lastColumn))
        'Copy the last checkbox with his VBA code
        Set chkBox = ActiveSheet.CheckBoxes(ActiveSheet.CheckBoxes.Count)
        chkBox.Copy
        ActiveSheet.CheckBoxes.Add(chkBox.Left, chkBox.Top + chkBox.Height + 5, chkBox.Width, chkBox.Height).Select
        ActiveSheet.Paste
    End Sub
    Last edited by Paul_Hossler; 04-01-2023 at 09:28 AM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •