samedi 1 avril 2023

copying an existing row which also copies the checkbox with its code

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. enter image description here

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




Aucun commentaire:

Enregistrer un commentaire