I need help with writing a macro that will insert a new row only one row above the main border of my template AND copy formulas down in that row .
My template is 25 rows long, with formulas in columns Q-R. I only want to allow the user to insert rows above row 23 (where I have one of the main borders), or whatever row it becomes after a new row has been added.
This means that when the user first opens the template, they have 22 rows to put data, if they need another row for more data, they will click a button and a new row will be added beneath it. Now, they have 23 rows of data and again, if they need another, they'll click the button. The macro will need to keep track where the main border is (initially on row 23, but now after two rows were added, it is now on row 25).
I had the code below, initially, but this allows the user to add a new row wherever the active cell they selected is located and it uses "double-click", not a button. My code needs to be limited to above row 23 starting off and tracking after any added row. I don't want them to be able to add a new row wherever, even if it is above the main border. A new row can only be inserted ONE row above the main border.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
ActiveSheet.Protect Password:="1234", UserInterfaceOnly:=True
With Target
.Offset(1).EntireRow.Insert
.EntireRow.Copy .Offset(1).EntireRow(1)
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
End With
End Sub
Bookmarks