Repeating Rows and Columns


Posted by Jack on June 09, 2001 4:47 PM

Excel gurus,

In a worksheet, I need to copy the first 60Rows and 5 columns and paste at the end of the first 60Rows and
repeat the process 100 times. Explaining further,
the first 60Rows gets copied to Rows61 to 120 and
again from Rows121 to 180 and so on for 100 times.

Is there a simple way to achieve this using a macro?
instead of the laborious copy and paste (of course
copy and paste the first set 9 times and copy the
whole 10 more times) or any other simpler way?

Appreciate any help on this

Posted by Eric on June 11, 2001 8:24 AM

think backwards: warning hack answer- not a guru

I do virtual basic like monkeys do nuclear physics (actually a lot like I do nuclear physics too), but I routinely have to do these kinds of manipulations, so here's what I do.
On sheet one, have your 60 rows of columns a and b layed out. Sheet two is blank.
start recording the macro and go to sheet 1 cell a1, then select your entire range of data (a1:b60). Copy the range, switch to sheet 2, use go to a1, and paste the range. Here's the important part, while the copied cells are still highlighted, insert 60 rows, then go back to sheet2, a1, back to sheet1, a1, and stop the macro recording. This actually adds to the list from the the top rather than the bottom but skips all of that "how do I find the end of my data?" stuff.
You could run the macro a hundred times, but GregC (about a month ago on this forum) showed me how to "for next" loop the macro using virtual basic. Go into the macro's script with Tools-->Macro and select the macro you recorded and hit Edit, there's the code for your macro in VBS. At the top of the black text add a line that says
for x = 1 To 100
and at the bottom of the black text add a line that says
next x
and it will loop your macro 100 times. Of course you only need to loop the "insert rows and paste" part of the macro, but as I said, Monkey, nuclear physics, this way works. Here's an example of what my script looks like running a model of your data as described.

For m = 1 To 100
Application.Goto Reference:="R1C1"
Range("A1:B1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Sheet2").Select
Application.Goto Reference:="R1C1"
ActiveSheet.Paste
Application.CutCopyMode = False
Application.CutCopyMode = False
Selection.EntireRow.Insert
Range("A1").Select
Sheets("Sheet1").Select
Selection.End(xlUp).Select
Next m

Posted by Jack on June 11, 2001 6:04 PM

Re: think backwards: warning hack answer- not a guru

Eric,

Thanks. Your monkey way did work.
I also figured a much easier way.
Highlighted the first 60R5C, using
the bottom right handle dragged
down while holding the ctrl key
all the way to 6000th row...

Cheers.

Posted by Eric on June 12, 2001 8:33 AM

Re: think backwards: warning hack answer- not a guru



Posted by Eric on June 12, 2001 10:34 AM

BTW my sets were unique data, not repeating labels

So the "fill" technique wouldnt be appropriate, but you have a much more direct solution for your problem, I should just go back to lurking! LOL