View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
dani dani is offline
external usenet poster
 
Posts: 13
Default Help revising slow code

I am using the following code to remove all the lines in a worksheet that
have a zero value in Column H. Because there are thousands of rows in the
worksheet, this loop takes forever! Does anyone have any suggestions for
doing this more quickly? Thanks!

Sub Delete_Row_w0()
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With Sheets(1)
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = .UsedRange.Cells(1).Row
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = LastRow To Firstrow Step -1

With .Cells(Lrow, "H")

If Not IsError(.Value) Then

If .Value = 0 Then .EntireRow.Delete

End If

End With

Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
.Calculation = CalcMode
End With

End Sub