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
 
I get the following Run-time error '1004':

Selection is too large.

I got to work just now for nine columns with 10 rows of data.

It does not work form B2 to BF2.

I have some worksheets where I require to be work for an even longer range.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Sure. lngLastRow creates the number of rows that pasted downwards.

Thanks.


Dim lngLastRow As Long

lngLastRow = Sheets("#Sheetnames2").Cells(Rows.Count, "C").End(xlUp).Row


Sheets("#Deal Banding Structure (1)").Range("B2:BF2").Copy _
Destination:=Sheets("#Deal Banding Structure (1)").Range("B2:BF" & lngLastRow)
 
Upvote 0
That code shouldn't cause an error, no matter how many times you copy it.

Does it error out on a specific line? If so, which line?
 
Upvote 0
It does not copy anything at all when the number is greater then about 650.

It works for fine when the number is lower.

Does it matter what the contents of the cells are? I have formulas in each one.

Thanks,

shivam03
 
Upvote 0
It shouldn't just stop unless one of your parameters is telling to.

Without seeing the code in its entirety, it's hard to say what's wrong, but you can try clearing the clipboard each time with Application.CutCopyMode = False, but I doubt that's it, since you're only copying a single range.
 
Upvote 0
Your idea did not work but thanks for the suggestion.

I tried testing the code in a new workbook sheet1 with just numbers and it worked fine.

I tried adding in formulas like the ones in my main workbook and it failed again. The formulas are quite long. e.g.

=INDIRECT(ADDRESS(MyEval("="&"MATCH("&"""COMMENTS"""&","&"'"&A2&"'"&"!A:A,0)")-2,3,,,A2))


I get the error selection is too large.

Do you think it is because the formulas are too long?

I used this code in the new workbook.

Sub test()
Dim lngLastRow As Long

lngLastRow = 500

Application.CutCopyMode = False

Sheets("Sheet1").Range("B2:BF2").Copy _
Destination:=Sheets("Sheet1").Range("B2:BF" & lngLastRow)
End Sub
 
Upvote 0
OK, for starters, that code's nothing like what we've been talking about at all. Not even close.

It's possible that you've blowing up what your workbook can handle by copying that many indirects, as it a very pricey formula. And the more complicated you make the formula the more overhead it takes up.

The code posted by itself can handle 65536 rows with no problem on my machine.

Note that you want CutCopyMode at the end.
 
Upvote 0
Okay, I guess you are right trying to copy such long formuals is the problem as it does work with simple formulas and numbers.

What did your code copy and paste on your machine? Was it just numbers in the worksheet?

Do you have any suggestions to overcome this? All I can think of is that I copy and paste a few columns at a time.

Thanks,

shivam03
 
Upvote 0
I copied =ROW()&COLUMN()

You might want to try copying, but turn off Calculation first and see what that does. If all those Indirects are taking up too much overhead while you're doing this then turning them off might help.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

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