I'm quite new to VBA and excel in general, so maybe a stupid issue, but I created two form buttons. One inserts an extra row with formulas and format, and the other one deletes a row. My problem is with the one that inserts a row. If I insert two rows there is no problem, when I try to insert a third row it gives me error 400. Can somebody explain what I'm doing wrong?
This is the only VBA I use:
Sub AddNewRow()
Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
r.Offset(-2).EntireRow.Copy
r.Offset(-1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
r.Offset(-2).EntireRow.PasteSpecial xlPasteFormats
r.Offset(-2).EntireRow.Borders(xlEdgeTop).LineStyle = xlNone
Application.CutCopyMode = False
End Sub
Sub DeleteLastRow()
Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
r.Offset(-2).EntireRow.Delete
Application.CutCopyMode = False
End Sub
This is the only VBA I use:
Sub AddNewRow()
Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
r.Offset(-2).EntireRow.Copy
r.Offset(-1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
r.Offset(-2).EntireRow.PasteSpecial xlPasteFormats
r.Offset(-2).EntireRow.Borders(xlEdgeTop).LineStyle = xlNone
Application.CutCopyMode = False
End Sub
Sub DeleteLastRow()
Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
r.Offset(-2).EntireRow.Delete
Application.CutCopyMode = False
End Sub