Improving code.....For Next
Mat wrote in message
om...
I would like to improve this code where I take 5 rows and when done
move to the other account which is different.
For b = 2 To 5000
lastrow = ActiveCell.Offset(5, 0).Row
Do Until b = lastrow
Cells(b, 7).Select
Range(Cells(b, 7), Cells(b, 10)).Select
Selection.Copy
Windows("RPACSTAR.XLS").Activate
Sheets("OUTPUT").Select
Range("A5000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Windows("RPX.XLS").Activate
b = b + 1
Loop
Exit For
Next b
You don't really need to move the activecell about! Below is the above code
compacted. I have missed the ""sheets("Output").select"" line out, this
sheet could be selected before the for next loop
For b = 2 To 5000
lastrow = ActiveCell.Offset(5, 0).Row
Do Until b = lastrow
Range(Cells(b, 7), Cells(b, 10)).Copy
Windows("RPACSTAR.XLS").Activate
Range("A5000").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteAll)
Windows("RPX.XLS").Activate
b = b + 1
Loop
Exit For
|