Can anyone give me VB code to delete a row if the cell value in a column = "0"? I'm new to the whole VB thing.
Based on the attached screenshot, I'm trying to remove the rows entirely if they have a zero in column E.
Dim n As Long, LastRow As Long
Dim myCrit As Range
LastRow = Range("E" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For n = LastRow To 2 Step -1
Set myCrit = Cells(n, 5)
If myCrit.Value = 0 Then Rows(n).EntireRow.Delete
Application.ScreenUpdating = True
Last edited by shades; 11-05-07 at 16:02.
old, slow, and confused
but at least I'm inconsistent!
Call DeleteRowswithValue(Cells(1, 1), 0)
Sub DeleteRowswithValue(rngColumn As Range, iValue As Integer)
Dim rngActive As Range
Dim bFoundCell As Boolean
bFoundCell = True
Do Until Not bFoundCell
'attempt to find the value
Set rngActive = rngColumn.EntireColumn.Find(what:=iValue, lookat:=xlWhole)
If Not rngActive Is Nothing Then
bFoundCell = False
Set rngfoundcell = Nothing
btw piere your method will fail if there is a blank value in the cell.
Also i would advice strongly against using select or selections if at all possible.
There are loads of ways to do this but shades has given a good answer if there is a limit on the amount of data