troubleshooting Question

Procedure going thru too many rows of data

Avatar of RWayneH
RWayneHFlag for United States of America asked on
Microsoft Excel
3 Comments2 Solutions91 ViewsLast Modified:
In the following code, the MaxRow is huge and causes the process to run a while.  How would I edit the following procedure to instead of using MaxRow, to only run for 500 lines? or as long as there is data in column M?  The file that it is failing on in attached.  When running this procedure the MaxRow value gets huge, and should need to get that big.  This adds significant runtime.  Is there a way to fix this?

Sub DelOOETranslations() 'Assumes that oldest or OOE are first
Dim WS As Worksheet
Dim MaxRow As Long, I As Long
Dim ThisDate As Date
Set WS = ActiveSheet
MaxRow = LastRow
I = 6

'---> Check for Cell if Date and Affect to ThisDate
    If Len(WS.Cells(I, "D")) = 20 And Mid(WS.Cells(I, "D"), 3, 1) = "/" Then
        ThisDate = DateValue(Left(WS.Cells(I, "D"), 10))
    End If
'---> Test if Date captured < now then delete or else increment counter go next line
    If ThisDate < DateValue(Now) Then
        WS.Cells(I, "A").EntireRow.Delete
        MaxRow = MaxRow - 1
        I = I + 1
    End If
Loop Until I > MaxRow

'---> Advise results to user
'MsgBox ("All date prior to " & DateValue(Now) & " have been deleted with their coresponding rows successfully.")
End Sub
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros