How do I make the following "For" VBA faster?

Wamhoi

New Member
Joined
Mar 4, 2011
Messages
48
Hi, I'm working with the following VBA to remove text/blank but its very slow when working with larger data files. Is there a way to make it faster?

For i = Lastline To 1 Step -1
If Not IsNumeric(Cells(i, 1).Value) Then Rows(i).Delete
If Cells(i, 1) = "" Then Rows(i).Delete
Next i
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi. Try

Code:
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = Lastline To 1 Step -1
    If Not IsNumeric(Cells(i, 1).Value) Then Rows(i).Delete
    If Cells(i, 1) = "" Then Rows(i).Delete
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
 
Upvote 0
Welcome to the forums!

Turn off screenupdating and calculations:

Code:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For i = Lastline To 1 Step -1
    If Not IsNumeric(Cells(i, 1).Value) Or Cells(i,1) = "" Then Rows(i).Delete
Next i 
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
 
Upvote 0
You might like to try this approach:

Code:
Dim rng As Range
Dim xlCalc As xlCalculation

With Application
  xlCalc = .Calculation
  .Calculation = xlCalculationManual
 End With

Set rng = Range("A1:A" & Cells(Rows.Count).End(xlUp).Row)

rng.Autofilter Field:=1,Criteria1:="*", Operator:=xlOr, Criteria2:="="

rng.Offset(1).EntireRow.Delete

rng.Autofilter

Application.Calculation = xlCalc
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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