My Task is I have to delete the entire Row if The K column Has zero value in it.First thing came to my mind is looping But i have 4000 rows and 1000 rows may have K value as zero.
Sub DeleteRowWithContents()
Last = Cells(Rows.Count, "D").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "K").Value) = 0 Then
Cells(i, "A").EntireRow.Delete
End If
Next i
End Sub
I believe People say Its Time taking Process as it is looping. Thats why I thought better go for next methods and People also told me 'Find' is much faster than looping. So I have used the below code That I found when I was googling
Sub Delete_zeros()
Dim rCell As Range
Dim strAddress As String
Application.ScreenUpdating = False
ThisWorkbook.Sheets(1).Activate
With ActiveSheet.Columns("K")
Set rCell = .Find(What:=0, LookIn:=xlValues, SearchOrder:=xlByColumns)
If Not rCell Is Nothing Then
Do
strAddress = rCell.Address
rCell.EntireRow.Delete
Set rCell = .FindNext(Range(strAddress))
Loop Until rCell Is Nothing
End If
End With
Application.ScreenUpdating = True
End Sub
But I found That the above code, it is also deleting the row if the k column has 10 or 20 Value in it. I mean if the Digit contains zero then its deleting
example .
204 or 200 or 205 or 301 or 10 \ Its deleting all these rows
Whats wrong with these code? These code is too fast than looping I wanted to use but I found bug with it.
Please explain the reason to the bug. And any help to other method which is faster in deleting the rows if it has zero value in K column other than looping or (might be also looping should be too fast )? That would be greatly appreciated. Thanks