Copy and Paste a number of rows depending on Input Value

merikev

New Member
Joined
Mar 27, 2014
Messages
5
Hi,
I have a macro that starts with an inputbox. It asks "how many samples would you like to add?" From the value that is input, I would like to copy a range of rows (that is already on my template) and paste as many times as the inputbox value states .

My Macro has started as

InputNum= Val(InputBox("How many more samples would you like to add?"))
If InputNum = 0 Then Exit Sub
If InputNum >0 Then ................... < this is where I dont know what to write.

Let me know if this needs clarification. Any help would be appreciated.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
try something like the below, but you may want to add other tests in, such as is it a number? is it a positive number? etc

Code:
Sub test()




InputNum = Val(InputBox("How many more samples would you like to add?"))
If InputNum = 0 Then Exit Sub


For i = 1 To InputNum


'Starts inputting the template data in A1:A5 but as i increase so does the range the template data outputs to
Sheets("Sheet1").Range("A1:A5").Offset((i - 1) * 6, 0).Value = Sheets("Template").Range("A1:A5").Value




Next i


1


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top