#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Loop

Hi

I have the follwoing loop,

finalrow = Worksheets("Daily Summary").Range("A65536").End(xlUp).Row
Set RNGd = Worksheets("Daily Summary").Cells(finalrow, 1)
Do Until Worksheets("Daily Summary").Range(RNGd, RNGd).Value = TodaysDate
Worksheets("Daily Summary").Range(RNGd, RNGd.Offset(0, 39)).Copy
Destination:=Worksheets("Daily Summary").Range(RNGd, RNGd.Offset(0,
39)).Offset(1, 0)
finalrow = Worksheets("Daily Summary").Range("A65536").End(xlUp).Row
Set RNGd = Worksheets("Daily Summary").Cells(finalrow, 1)
Loop

Which basically checks the last cell in column A and if the date isn't equal
to today, it copies that row to the next empty row. The loop keeps going
until the final cell is equal to todays date.

1) Is there a better way of writing this code.

2) Specifically, I have to keep restating the final row and RNGd, can this
be avoided.

Thanks and Regards
Richard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Loop

Here arre two solutions that are very similar. The second copies the entire
row rather than the range A to AM. The destination of a copy only has to be
the first cell in most cases.

Sub test()

finalrow = Worksheets("Daily Summary").Range("A65536").End(xlUp).Row

Do Until Worksheets("Daily Summary").Range("A" & finalrow).Value = TodaysDate
Worksheets("Daily Summary").Range("A" & finalrow & ":AM" &
finalrow).Copy _
Destination:=Worksheets("Daily Summary").Range("A" & (finalrow + 1))
finalrow = finalrow + 1
Loop


End Sub
Sub test2()

finalrow = Worksheets("Daily Summary").Range("A65536").End(xlUp).Row

Do Until Worksheets("Daily Summary").Range("A" & finalrow).Value = TodaysDate
Worksheets("Daily Summary").Rows(finalrow).Copy _
Destination:=Worksheets("Daily Summary").Rows(finalrow + 1)
finalrow = finalrow + 1
Loop


End Sub


"Richard" wrote:

Hi

I have the follwoing loop,

finalrow = Worksheets("Daily Summary").Range("A65536").End(xlUp).Row
Set RNGd = Worksheets("Daily Summary").Cells(finalrow, 1)
Do Until Worksheets("Daily Summary").Range(RNGd, RNGd).Value = TodaysDate
Worksheets("Daily Summary").Range(RNGd, RNGd.Offset(0, 39)).Copy
Destination:=Worksheets("Daily Summary").Range(RNGd, RNGd.Offset(0,
39)).Offset(1, 0)
finalrow = Worksheets("Daily Summary").Range("A65536").End(xlUp).Row
Set RNGd = Worksheets("Daily Summary").Cells(finalrow, 1)
Loop

Which basically checks the last cell in column A and if the date isn't equal
to today, it copies that row to the next empty row. The loop keeps going
until the final cell is equal to todays date.

1) Is there a better way of writing this code.

2) Specifically, I have to keep restating the final row and RNGd, can this
be avoided.

Thanks and Regards
Richard

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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 06:01 AM.

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"