Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mat Mat is offline
external usenet poster
 
Posts: 3
Default Improving code.....For Next

I would like to improve this code where I take 5 rows and when done
move to the other account which is different.

Thx

Mat

'Loop for Positive

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

For c = b To 2000

If Cells(c, 7) < Cells(c + 1, 7) Or Cells(c, 8) < Cells(c + 1, 8)
Then
Cells(c + 1, 7).Select
Exit For
End If

Next c

For d = c + 1 To 2000

lastrow = ActiveCell.Offset(5, 0).Row

Do Until d = lastrow
Cells(d, 7).Select
Range(Cells(d, 7), Cells(d, 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
d = d + 1
Loop
Exit For

Next d

For e = d To 2000

If Cells(e, 7) < Cells(e + 1, 7) Or Cells(e, 8) < Cells(e + 1, 8)
Then
Cells(e + 1, 7).Select
Exit For
End If

Next e
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Improving code.....For Next


even better....(the long line begining with Windows may of wrapped!)

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").Worksheets("Output").Range ("A5000").End(xlUp).Offset
(1, 0).PasteSpecial (xlPasteAll)
b = b + 1
Loop
Next b

Stuart wrote in message
...

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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Improving code.....For Next

Why not do it all in one step?

Cells(2, 7).Resize(ActiveCell.Offset(5, 0).Row - 2, 4).Copy _
Destination:=Workbooks("RPACSTAR.XLS").Worksheets( _
"Output").Range("A5000").End(xlUp).Offset(1, 0)

or, if you just want to copy values, you can avoid the Copy
altogether:

With Cells(2, 7).Resize(ActiveCell.Offset(5, 0).Row - 2, 4)
Workbooks("RPACSTAR.XLS").Worksheets( _
"Output").Range("A5000").End(xlUp).Offset(1, 0).Resize( _
.Rows.Count, .Columns.Count).Value = .Value
End With

In article ,
"Stuart" wrote:

even better....(the long line begining with Windows may of wrapped!)

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").Worksheets("Output").Range ("A5000").End(xlUp).Offset
(1, 0).PasteSpecial (xlPasteAll)
b = b + 1
Loop
Next b

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Improving the Discussion Boards Jeremy Excel Discussion (Misc queries) 1 February 12th 08 09:34 PM
Improving formula Brad Excel Worksheet Functions 1 April 6th 06 06:02 PM
Improving use of Worksheets TKeune Excel Worksheet Functions 2 February 11th 06 10:59 AM
Improving speed with VBA Steven Cheng[_2_] Excel Programming 7 October 12th 03 05:37 PM
need help in improving this macro mcm Excel Programming 0 August 28th 03 04:32 AM


All times are GMT +1. The time now is 04:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"