Loop to copy and paste

shivam03

Board Regular
Joined
Nov 22, 2010
Messages
86
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Thanks for taking time to read this. <o:p></o:p>
<o:p></o:p>
I have thought of solution to a previous question I posted but need some help to get it started. I have some code that copies and pastes a row of data downwards. The issue is that when I get the code to copy the contents of cells B2 to BF2 downwards by more than 650 rows it does not work.<o:p></o:p>
<o:p> </o:p>
Please can someone help me with the following -<o:p></o:p>
<o:p></o:p>
I have the following values in cells B2 to K2.<o:p></o:p>
<o:p></o:p>
1 =B2 =C2 =D2 =E2 =F2 =G2 =H2 =I2 =J2 =K2<o:p></o:p>
<o:p></o:p>
I would like to have the contents of cells B2 to F2 copied down by 10 rows and then cells G2 to K10 by 10 rows.<o:p></o:p>
<o:p></o:p>
I essentially want to have a loop that will do this a number of times. E.g. I might need to copy 50 columns in groups of 5.<o:p></o:p>
<o:p> </o:p>
Eventually I want to have the number of rows it copies downwards as a variable but will keep it simple for now.<o:p></o:p>
<o:p> </o:p>
Thanks a lot<o:p></o:p>
<o:p></o:p>
shivam03
 

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).
You should stick to your original thread, especially if there's meaningful content there, like your code.
 
Upvote 0
Okay, sure. I will make sure I will do that in the future.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I guess in this case it does not matter that original code is not shown as I qm trying to find an alternative solution based on this simpler example.<o:p></o:p>

Hopefully somebody can help.<o:p></o:p>

<o:p></o:p>
Thanks,<o:p></o:p>
<o:p></o:p>
shivam03<o:p></o:p>
 
Upvote 0
Well, see if this gets you started:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, LR <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>        x = 10<br>            <SPAN style="color:#00007F">For</SPAN> y = 1 <SPAN style="color:#00007F">To</SPAN> 5<br>                LR = Cells(Rows.Count, "B").End(xlUp).Offset(1).Row<br>                Range("B2:K2").Copy Range("B" & LR & ":K" & LR).Resize(10)<br>            <SPAN style="color:#00007F">Next</SPAN> y<br>            <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0
Hi there,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Thanks for this.<o:p></o:p>

<o:p></o:p>
I think this is not exactly what I am looking for but I could be wrong.<o:p></o:p>
<o:p></o:p>
I would like the code to copy and paste cells B2 to F2 downwards by 10 rows.<o:p></o:p>
<o:p></o:p>
After this G2 to K2 downwards by 10 rows.<o:p></o:p>
<o:p></o:p>
Eventually I would like to make it look so it can do the same for the next five columns, e.g. L to P and so on. That is why I think a loop would be perfect.<o:p></o:p>
<o:p></o:p>
I will make the 10 rows a variable eventually.<o:p></o:p>
<o:p></o:p>
Please let me know if you any ideas.<o:p></o:p>
<o:p></o:p>
Thanks so much, your time and help is much appreciated.<o:p></o:p>
<o:p></o:p>
shivam03 <o:p></o:p>
<o:p> </o:p>
 
Upvote 0
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I did try it. I think I probably have not explained what I needed very well, sorry.<o:p></o:p>
<o:p></o:p>
I need to copy the data in cells B2 to F2 downwards by 10 rows and then cells G2 to K2 downwards by 10 rows and then stop.<o:p></o:p>
<o:p></o:p>
There should only be 10 rows of data in the end.<o:p></o:p>
<o:p></o:p>
I want the loop to work so I can choose how many groups of 5 columns to copy and paste data downwards.<o:p></o:p>
<o:p> </o:p>
So if I choose three, it would do B2 to F2, then G2 to K2 and then finally L2 to P2.
Thanks,
shivam03
 
Upvote 0
No, you didn't explain that earlier.

Regardless, does the code do what you were asking for in the first post? If so, then it's easy to put in the column breaks and copy 3 separate ranges. But let's see how close the code got to overall need for now.
 
Upvote 0
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
The code in the first post does works for about 500 rows. <o:p></o:p>
<o:p></o:p>
It does not work for 650+ due to the amount of memory I am asking it to hold.<o:p></o:p>
<o:p></o:p>
I can get it to work when I work in groups of 3-5 columns.<o:p></o:p>
<o:p></o:p>
That is why I thought a loop would be the quickest way to achieve this.<o:p></o:p>
<o:p></o:p>
Does that make sense? I can provide more information.<o:p></o:p>
<o:p></o:p>
Thanks again,<o:p></o:p>
<o:p></o:p>
shivam03<o:p></o:p>
<o:p> </o:p>
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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