My Row delete code is soooooo slow......... need cleanup and/or modification please

Javi

Active Member
Joined
May 26, 2011
Messages
440
Hi All,

The two codes below delete each EntireRow that has "Function carried out" in column I of its row. However, the sheet I am using this code on has approximately 40,000 lines occupied. Code 1 is a little faster than Code 2 but both of them are so slow there almost unusable.

Any help or assistance in speeding up this would be greatly appreciated.



Code 1

Code:
Sub SelRows_After1()
    Dim ocell As Range
    Dim rng As Range
    
    For Each ocell In Range("I3:I40000")
        
        If ocell.Value = "Function carried out" Then
            
            If rng Is Nothing Then
                
                Set rng = ocell.EntireRow
            Else
                
                Set rng = Union(rng, ocell.EntireRow)
            End If
        End If
    Next
    
     
    If Not rng Is Nothing Then rng.Delete
    
    Set rng = Nothing
    Set ocell = Nothing
End Sub


Code 2

Code:
Sub DelRow_FCO()




Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False




Dim DeleteRow As Long
Dim ws As Worksheet




Set ws = ActiveSheet


For DeleteRow = ws.Range("I" & Rows.Count).End(xlUp).Row To 3 Step -1


If ws.Range("I" & DeleteRow).Value = "Function carried out" Then
    Rows(DeleteRow).EntireRow.Delete
    End If
    
Next DeleteRow




Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True




End Sub
 
Close all programs restart computer and new codes are running perfectly. Thanks all for your help.

Sometimes it's the most basic solution, restart your computer, I did not live by my own advice.

Thanks again!!!
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top