ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro (https://www.excelbanter.com/excel-programming/308379-macro.html)

No Name

macro
 
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?

Frank Kabel

macro
 
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


--
Regards
Frank Kabel
Frankfurt, Germany


wrote:
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?


Ron de Bruin

macro
 
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



--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message ...
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?





All times are GMT +1. The time now is 03:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com