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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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