LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default VBA (Optimization) Help to replace inefficient Do .. Loops ...

Hi,

I have several Do.. Loops in different Case statements in a sub like this:
CODE <<<<

[P3].Select

' Autofilter didn't work properly, so deleting ALL non-SETL
rows...
' FOR THIS REASON, it is important to run the SETTLED LAST !!!
Do Until ActiveCell.Text = ""

If ActiveCell.Text < "SETL" Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If

Loop

'hide the lines with the excluded broker numbers
[S3].Select

Do Until ActiveCell.Text = ""
For iExCount = 0 To UBound(iExcludedBrks)
If ActiveCell.Text = iExcludedBrks(iExCount) Then
ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
Exit For
End If
Next
ActiveCell.Offset(1, 0).Select
Loop

Columns("R:R").Hidden = False ' LAST UPDATE COLUMN MUST NOT BE HIDDEN !!!
[R3].Select

' first loop, delete ALL rows with LAST UPDATE before LAST RUN, as these are
ALL SETTLED !
Do Until ActiveCell.Text = ""
NextDate:
If ActiveCell.Text = "" Then Exit Do
iTestDate = CDate(Format(VBA.Left(VBA.Trim(ActiveCell.Text),
4) & "/" & VBA.Mid(VBA.Trim(ActiveCell), 5, 2) & "/" &
VBA.Mid(VBA.Trim(ActiveCell), 7, 2), "Short Date"))

If iTestDate < CDate(sLastUpdateDate) Then
' this LAST UPDATE was before LAST RUN DATE , so now time check required,
delete
ActiveCell.EntireRow.Delete shift:=xlUp

GoTo NextDate
End If
ActiveCell.Offset(1, 0).Select

Loop

[R3].Select
' now we have deleted ALL activity that settled BEFORE the LAST RUN, so with
the remainder,
' check the time part of the LAST UPDATE FIELD AGAINST TIME LAST RUN !!!
' Modified PWL 2002 02 26
' To force a test of BOTH conditions ...
' Both the DATE of LAST UPDATE AND TIME LAST UPDATE in MCH MUST
be before LAST RUN date/time
' for a record to be deleted...
Do Until ActiveCell.Text = ""
NextTime:
If ActiveCell.Text = "" And ActiveCell.Offset(1, 0).Text =
"" Then Exit Do

' iTestTime = TimeValue(VBA.Left(VBA.Right(VBA.Trim(ActiveCell.T ext), 6),
2) & ":" & VBA.Mid(VBA.Right(VBA.Trim(ActiveCell.Text), 6), 3, 2) & ":" &
VBA.Right(VBA.Right(VBA.Trim(ActiveCell.Text), 2), 6))

' it tests the values of the 'seconds' part of the DATE TIME LAST UPDATE
field from
' MCH, and if that is = 60 then it is replaced by 59.
' CHANGED PWL, Aug 2003 for MCH Issue in CTDA/BTDA...
If VBA.Right(VBA.Right(VBA.Trim(ActiveCell.Text), 2), 6) = 60 Then
iTestTime =
VBA.TimeValue(VBA.Left(VBA.Right(VBA.Trim(ActiveCe ll.Text), 6), 2) & ":" &
VBA.Mid(VBA.Right(VBA.Trim(ActiveCell.Text), 6), 3, 2) & ":59")
Else
iTestTime =
VBA.TimeValue(VBA.Left(VBA.Right(VBA.Trim(ActiveCe ll.Text), 6), 2) & ":" &
VBA.Mid(VBA.Right(VBA.Trim(ActiveCell.Text), 6), 3, 2) & ":" &
VBA.Right(VBA.Right(VBA.Trim(ActiveCell.Text), 2), 6))
End If
iTestDate = CDate(Format(VBA.Left(VBA.Trim(ActiveCell.Text), 4) & "/" &
VBA.Mid(VBA.Trim(ActiveCell), 5, 2) & "/" & VBA.Mid(VBA.Trim(ActiveCell), 7,
2), "Short Date"))

' check the last UPDATE TIME OF THE RECORD against LAST RUN TIME
' BY THE SECOND !!!
If (iTestTime < TimeValue(sLastUpdateTime)) And (iTestDate =
CDate(sLastUpdateDate)) Then
' e.g. IF time of LAST RUN was 09:01:00 and Time LAST UPDATE was 09:00:59
' THEN THAT ROW WILL BE DELETED !!!
' Time of last update was BEFORE last run, so delete
this row!
ActiveCell.EntireRow.Delete shift:=xlUp
GoTo NextTime
End If
ActiveCell.Offset(1, 0).Select
Loop

<<< END CODE

I am sure there must be a better way... for example, I have a list of
brokers to exclude from the report in an array, and for each row I check all
the brokers...

I'd be gratefule for any help to replace this with more efficeint code in
case there are many thousands of trades being checked...

thanks

Philip
 
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
Inefficient? Steph[_3_] Excel Programming 3 April 19th 05 08:48 PM
Arrays to replace very slow loops ? vbastarter Excel Programming 5 August 10th 04 07:15 PM
Inefficient Space Removal Sauron Excel Programming 5 January 2nd 04 11:03 AM
Loop worked but is it inefficient? Bob Phillips[_5_] Excel Programming 2 August 13th 03 12:10 AM
Loop worked but is it inefficient? steve Excel Programming 2 August 12th 03 09:16 PM


All times are GMT +1. The time now is 05:40 PM.

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

About Us

"It's about Microsoft Excel"