Hello, 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
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 getNum: 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 Selection.Copy Rows(Selection.Row + 1 & ":" & Selection.Row + myCopyNum).Insert Shift:=xlDown End SubClick Here Before Posting Data or VBA Code ---> How To Post Data or Code.
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.
Ricky
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |