We help IT Professionals succeed at work.

Procedure going thru too many rows of data

RWayneH asked
Last Modified: 2014-08-20
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

Open in new window

Watch Question

Top Expert 2016
This one is on us!
(Get your first solution completely free - no credit card required)
NorieAnalyst Assistant
This one is on us!
(Get your first solution completely free - no credit card required)


Thanks, both worked.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.