Solved Macro to copy, paste, insert in Excel

March 12, 2013 at 09:46:34
Specs: Windows 7

I am trying to do the following - I have a data sheet with about 100 rows, and would like to write a macro where it copies a selected row and inserts /pastes directly underneath it a specified number of times.

e.g. user selects row 5 and wants that data to be repeated 17 times underneath it.

Any help you can give would be great,
thanks, Ricky

See More: Macro to copy, paste, insert in Excel

Report •

March 12, 2013 at 13:07:53
✔ Best Answer
Sub InsertRows()
'Make sure user has selected 1 entire row
  If Selection.Cells.Count <> Selection.Resize(1).EntireRow.Cells.Count Then
   MsgBox "Please select 1 entire row, then rerun macro."
   Exit Sub
  End If
'Get number of rows to insert from user
   myCopyNum = Application.InputBox("How Many Times Do You Want the Row Copied", Type:=1, Default:=0)
'Make sure sneaky users can only enter integer values
     If Int(myCopyNum) <> myCopyNum Then
        MsgBox "Enter Integer Value or Click Cancel"
        GoTo getNum
     End If
'Quit if Cancelled
     If myCopyNum = False Then Exit Sub 'Copy and Insert Rows
         Rows(Selection.Row + 1 & ":" & Selection.Row + myCopyNum).Insert Shift:=xlDown
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

March 14, 2013 at 07:34:29
DerbyDad03 -- thanks so much, this code works perfectly for what I need. you have saved me a lot of time and made my life considerably easier.

Thanks again.

Report •

Related Solutions

Ask Question