I have a spreadsheet with multiple tabs and each tab has a table. I want a button per tab to insert rows to the bottom of that table (by not having to select a cell) and copy the formulas from the row above it. Here is what I have:
-ask how many rows to insert -default insert is 1 -otherwise, use that variable to insert at bottom and copy formulas
Sub InsertRows()
Dim i As Long
Dim j As Variant
j = InputBox("How many rows would you like to add?", "Insert Rows")
If j = "" Then
j = 1
End If
For i = 1 to j
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
With newrow.Range
.Offset(-1).Copy
.Cells(1).PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
End With
Next
End Sub
I'm not sure how to implement the i
and j
from the input into the For
loop.