I am automatically generating rows on my Excel with user input data from a form
They click a button, it pops up the Form, they fill in their data and it adds it to the rows.
With this I want to create a "remove row button" at the end of these inserted rows.
that the button when clicked will remove the row and the button.
Declared variables
![]()
Dim iRow As Long Dim ws As Worksheet Dim btn As Button Set ws = Worksheets("Sheet1")
I create the rows
![]()
ws.Cells(iRow, 2).Offset(1).EntireRow.Insert ws.Cells(iRow, 6).Copy ActiveSheet.Paste Destination:=ws.Cells(iRow, 6).Offset(1)
the data fills into the rows from all the user fields...
I then create the button
![]()
Application.ScreenUpdating = False Set btn = ws.Buttons.Add(ws.Cells(iRow, 9).Left, ws.Cells(iRow, 9).Top, ws.Cells(iRow, 9).Width, ws.Cells(iRow, 9).Height) With btn .Caption = "Remove Row" .Name = "remove" & iRow .OnAction = DoNothing End With Application.ScreenUpdating = True
This lands it in the 9th Column of the Row I just created
I currently have OnAction set to do nothing, just so it doesn't error out
but I have tried setting the OnAction to remove the button itself
![]()
ws.Shapes("remove" & iRow).delete
but it errors out, as I am not sure what is off with this.
I also tried setting the OnAction to delete the Inserted Row it was created on, but couldn't get that to function either.
and I need the created button to do both actions.
As later on I want to lock the excel, and leave these generated buttons as the only way to remove the rows they create.
Bookmarks