PDA

View Full Version : Excel VBA Macro To Repeat Records Based On User Value In InputBox



gclifton
02-12-2016, 03:05 AM
Is there a way to Modify this Macro to read a list of Number in Sheet 2, by Cell A1 then A2, etc (loop) for example the table below would reflect what is in Sheet 2.Then take that number in Sheet 2 A1 and place it in Column U with all the Data and then copy and Duplicate "A1:"U189" beside me having to put the total number or repetitions in the Input Box. So now basically the Macro is now labeling all that is being Copied by Sheet 2 A1, A2,. So in my example 101 would have 189 lines labeled as 101 and 102 will have 189 labeled as 102




Dim rng As Range
Dim i As Long

Set rng = Range("A1:T189")
For i = 1 To InputBox("Enter repetitions")
rng.Copy rng.Offset(rng.Rows.Count * i)
Next i


101
102
103
104
105

bakerman
02-12-2016, 10:26 AM
Dear gclifton,

Welcome to the forum. Although here it's not against forum rules most helpers do not appreciate crossposting.(putting your question in multiple forums)
Since all helpers here do this in their spare time and free of charge it's common policy to provide a link(s) to the other forum where you put your question so they can check progress and don't waste their time on solving a question which might already be answered elsewhere.
Is your question answered elsewhere post a message here saying so and mark your thread as solved.
If you do not comply to this next time you crosspost without a link your thread will be closed.

VBA Input Box (http://www.mrexcel.com/forum/excel-questions/920777-visual-basic-applications-input-box.html)

Excel Fox
02-12-2016, 04:32 PM
gclifton, please use VBA code tags to wrap your code.

On your question, can you attach a sample workbook with pre and post examples. That will make it easy for a developer to create a macro for you.