I have a excel spread sheet where I have added a button on a row which I wanted to click, take a copy of that row and then duplicate underneath.
For some reason it does not seem to be selecting the row where I click the button but where ever the cursor is meaning the wrong line is copied.
Is there any way I can change the below to make the active cell where ever the button has just been pressed ?
Sub InsertRows()
Dim x As Integer
x = Application.InputBox("Number of Rows", "Number of Rows", Type:=1)
If x = False Then Exit Sub
ActiveCell.EntireRow.Copy
Range(ActiveCell, ActiveCell.Offset(x - 1, 0)).EntireRow.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub
Many thanks in advance
Terran
EDIT
My final solution with Thomas' help.
The slight difference is that this allows the button its self to also be copied as well as the row.
Sub InsertRows()
Dim iRow As Integer
Dim x As Integer
Dim i As Integer
x = Application.InputBox("Number of Rows", "Number of Rows", Type:=1)
iRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
If x = False Then Exit Sub
For i = 0 To (x - 1)
'Range(ActiveCell, ActiveCell.Offset(x - 1, 0)).EntireRow.Insert Shift:=xlDown
Range("A" & iRow).EntireRow.Copy
Range("A" & iRow + 1 + i).EntireRow.Insert Shift:=xlDown
Next i
Application.CutCopyMode = False
End Sub