macro

G

Guest

I need the code that will Delete the entire row if the
cell in Column I is equal to zero. I need it to go down
the whole column. Can anyone help me out?
 
F

Frank Kabel

Hi
try the following macro:
Sub delete_rows()
Dim lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, "I").End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Cells(row_index, "I").Value = 0 then
rows(row_index).delete
End If
Next
Application.ScreenUpdating = True
End Sub

also have a look at:
http://www.xldynamic.com/source/xld.Deleting.html
 
R

Ron de Bruin

Try this for column I

Sub Example1()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long

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

Firstrow = ActiveSheet.UsedRange.Cells(1).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1
With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1
If IsError(.Cells(Lrow, "I").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "I").Value = "0" Then .Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
 
Top