Quickest way to delete rows

y0gster

New Member
Joined
Apr 12, 2011
Messages
4
I have basically hit a wall with this problem since switching to office 2007. In office 2003 the whole code ran 4 seconds.

This is the portion that slows it down, this is the code that came from office 03 and in 07 it took 30 seconds to run. (Basically the whole code is running this portion 3x since it will go through 3 sheets). So the total time would go to 1min 20 seconds. This is already with screenupdating to false and calculation to manual.

For i = 2 To Range("A65536").End(xlUp).Row
If Range("A" & i).Value <> "" And Range("H" & i).Value = "" Then
Rows(i & ":" & i).Delete Shift:=xlUp
i = i - 1
End If
Next i

I then decided to change the code to

Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete

This would take 12 seconds each putting the total time to around 40 seconds

I know I already cut the time to 50% but is there any faster way to do this. TIA
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi, try
Code:
Application.ScreenUpdating = False
For i = Range("A" & Rows.count).End(xlUp).Row To 2 Step -1
    If Range("A" & i).Value <> vbNullString And Range("H" & i).Value = vbNullString Then
       Range("A" & i).EntireRow.Delete
    End If
 Next i
Application.ScreenUpdating = True
 
Last edited:
Upvote 0
Thanks kpark but the code actually got slower going on for 40 seconds each making the total 1 min and 30 seconds
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

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