Copy/Paste based on cell value

bustakaps9

New Member
Joined
Sep 14, 2011
Messages
6
I'm having trouble sheet pictured below. I'm trying to copy and paste each row "x" number of times, based on the value in column D.

Any help is GREATLY appreciated, as I don't even know where to start with this!

vnhx6f.jpg
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Welcome to the Board!

You'll need VBA for that (but it's easy). Where do you want the copied rows to be pasted?
 
Upvote 0
See if this gets you started:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range([A2], Cells(Rows.Count, "A").End(xlUp))<br>            <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> Cells(c.Row, "D").Value<br>                Cells(c.Row, 1).EntireRow.Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1)<br>            <SPAN style="color:#00007F">Next</SPAN> i<br>        <SPAN style="color:#00007F">Next</SPAN> c<br>        <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Perfect! Thanks so much for your help!!!! Any suggestions on where to go to learn VBA? I'm fairly proficient with excel, but when it comes to macros, unless I can record it (I know that's not the right way), I'm clueless... I'd love to understand what each of those statements in there means.

Thanks again for the help!
 
Upvote 0
You can do a Bingle search for "Free VBA Tutorials" and turn up a lot of stuff. Martin Green's got some good ones at www.fontstuff.com.

You can also find the VBA Developer's Reference on www.msdn.com, but it's pretty technical.

Zack Barresse and I have a few articles here as well.

Another good way is to just lurk the VBA posts and see what's going on, in addition to asking your own questions.

One of the first things to learn about recorded code is that it's often inefficient, so most of the screen navigation calls you can lose, and when you see "Select" followed by "Selection" you can usually get rid of both statements and concatenate the remaining code (it's generally not necessary to select things in order to work with them).
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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