
Subject: Subject: Using A LOOP In A Macro (Newbie)
Nick,
Here is a possible use for you.
If there are no breaks in the data going down the sheet, then
dim lLine as Long ' This is for the second sheet
lLine = 1
while activecell.value <> ""
activecell.entirerow.select
selection.copy
sheets("Sheet2 <or what ever your sheet is>").select
rows(lline).select
activesheet.paste
lLine = lLine + 1
sheets("Sheet1").select
Application.CutCopyMode = False
activecell.offset(1).select
wend
If there are breaks and you want to use a line/row to stop change
activecell.value to activecell.row < "Your value"
Basically, you are looping down the sheet and copying the values to a new
activesheet.
Note that the screen will bounce like a yo-yo. To stop that, insert the line
Application.screenupdating = false ' at the beginnig
Application.screenupdating = true ' at the end
Again, there are many different solutions that will work. The goal is to
find one that you like
and that fits the situation.
I hope this helps.
Justin
Quote:
> Hello Everyone.
> I've recorded a macro that copies and pastes a row into another
> worksheet. The problem is I need to put this into a loop so that it
> will copy and paste a further 1500 rows. The existing macro code is as
> follows:
> Sheets("Base").Select
> Rows("7:7").Select
> Selection.Copy
> Range("A2").Select
> ActiveSheet.Paste
> Sheets("KMA Parts demands").Select
> Range("A2:P2").Select
> Range("P2").Activate
> Application.CutCopyMode = False
> Selection.Copy
> Range("R2").Select
> Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
> SkipBlanks:= _
> False, Transpose:=False
> How can I put this in a loop so that the
> Rows("7:7").Select
> part will be incremented by +1 and the
> Range("R2").Select
> part will be incremented by +1 each time also.
> Many thanks to anyone who can help a Newbie,
> Nick.