I am trying to find each cell that contains the following value "# Results" and if the cell to the right is == 0 then delete the entire row as well as the row below.
However, since I am deleting rows, the .Range.Find method gets buggy and fails to find the next occurence after the first deletion. How can I make this code work?
Here is the code:
sub KillEmptyResults()
Dim sRows As Range
Dim X As Range
Set X = Nothing
SearchStr = Chr(35) & " Results"
With ActiveSheet.UsedRange
Set X = .Cells.Find(What:=SearchStr, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not X Is Nothing Then
sFirstAddress = X.address
Do
'Transform anchor row to entire range to delete
If X.Offset(0, 1).Value = "0" Then
Set sRow = Rows(X.Row).EntireRow
Set sRows = sRow.Resize(sRow.Rows.Count + 1, sRow.Columns.Count)
sRows.Delete
End If
Set X = .FindNext(X)
Loop While Not X Is Nothing And X.address <> sFirstAddress
End If
End With
End Sub
Thank you