0

I want to delete any row with a numeric value in a cell. When I run the following code it correctly evaluates the IsEmpty and IsNumeric() functions and deletes the row. However it stops for some reason and will complete after 3 tries. Note: I've tried Cell.Value and Cell.Value2.

For Each Cell In Range("H1:H600")
    If Not IsEmpty(Cell) Then
        If IsNumeric(Cell.Value) Then
            Cell.EntireRow.Delete
        End If
    End If
Next
4
  • 1
    when deleting go from the bottom up, you'll get much more consistent results. Commented Aug 4, 2016 at 19:25
  • 1
    that's because when you delete a row, the other rows get bumped up. If you delete 1 reduce i by i=i-1 Commented Aug 4, 2016 at 19:26
  • 1
    You need to loop backwards or it will skip lines. See here for three options; stackoverflow.com/questions/33744149/… Commented Aug 4, 2016 at 19:27
  • 1
    Possible duplicate of Removing rows without skipping a row how to? Commented Aug 4, 2016 at 19:33

1 Answer 1

1

If you don't have formulas in that range:

Range("H1:H600").SpecialCells(xlCellTypeConstants, xlNumbers).EntireRow.Delete
Sign up to request clarification or add additional context in comments.

3 Comments

I was thinking the same but some of his numbers might be stored as text
That will also remove any numbers formatted as text
Apologies for the late reply. This worked and is obviously a lot fast than what I had. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.