Procedure going thru too many rows of data

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

Do
'---> 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
    Else
        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

Open in new window

Translation.xlsx
RWayneHAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try (changed line 6)
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 = Range("A" & Cells.Rows.Count).End(xlUp).Row
I = 6

Do
'---> 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
    Else
        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

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieVBA ExpertCommented:
This will set MaxRow to be the last row in column M.
MaxRow = ActiveSheet.Range("M" & Rows.Count).End(xlUp).Row

Open in new window

0
RWayneHAuthor Commented:
Thanks, both worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.