Macro to paste multiple times based on user input

liddy4879

New Member
Joined
Feb 7, 2022
Messages
2
Platform
  1. Windows
Hello! I am looking to have a macro that will copy a selection of cells (A12-G13) that are serving as a template and paste it multiple times below and the number of times it is pasted is based on a user input that would be promped in an input box when the macro is started?
 

Attachments

  • Before.PNG
    Before.PNG
    17 KB · Views: 40
  • After.PNG
    After.PNG
    39.6 KB · Views: 39

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Welcome to the Board!

Try this:
VBA Code:
Sub MyCopy()

    Dim c As Integer
    Dim e As Integer
    
'   Prompt user for how many times they would like to copy
    c = InputBox("How many copies would you like to make?")
    
'   Calculate ending row
    e = (c * 2) + 13
    
'   Copy from A12:G13
    Range("A12:G13").Copy Range("A14:A" & e)
    
End Sub
 
Upvote 0
Solution
Welcome to the Board!

Try this:
VBA Code:
Sub MyCopy()

    Dim c As Integer
    Dim e As Integer
   
'   Prompt user for how many times they would like to copy
    c = InputBox("How many copies would you like to make?")
   
'   Calculate ending row
    e = (c * 2) + 13
   
'   Copy from A12:G13
    Range("A12:G13").Copy Range("A14:A" & e)
   
End Sub
Thank you, this works great!
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0
Hi Joe, Thanks for the speedy response. Unfortunately this does not work for me.
Attached is what I am trying to accomplish. Enter a number in F1 (x) and range A2:D2 is duplicated (x) times
 

Attachments

  • Duplicate.JPG
    Duplicate.JPG
    25.8 KB · Views: 15
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

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