0

I am looking to implement a VBA routine which deletes automatically anything in column I&J which has the word 'delete' in it because this is a validation return which I have set up. I have the following code, yet my code breaks on the second loop whereby I get a subscript out of range. Haven't been able to fix it so if someone could give advice, would be much appreciated.

Sub RemoveNA()
'THIS DELETES ALL ROWS WHERE THE VALUE IN COLUMN I IS "DELETE"
    Dim FoundCell As Range
    Application.ScreenUpdating = False
    Set FoundCell = Range("I:I").Find(what:="DELETE", LookIn:=xlValues)
    Do Until FoundCell Is Nothing
        FoundCell.EntireRow.Delete
        Set FoundCell = Range("I:I").FindNext
    Loop

    'THIS DELETES ALL ROWS WHERE THE VALUE IN COLUMN J IS "DELETE"
    Application.ScreenUpdating = False
    Set FoundCell = Range("J:J").Find(what:="DELETE", LookIn:=xlValue)
    Do Until FoundCell Is Nothing
        FoundCell.EntireRow.Delete
        Set FoundCell = Range("J:J").FindNext
    Loop

End Sub
1
  • Don't use Application.ScreenUpdating = False twice. Just use it once in the beginning and set it to True at the end. Second, just change FoundCell to check Range("I:J"). Two loops are unnecessary when you can do it with one. Third, missing s in LookIn:=xlValues in second loop. Commented Jul 21, 2014 at 16:25

1 Answer 1

1

Looks like you're missing the 's' in 'LookIn:=xlValue' in the second loop.

Sign up to request clarification or add additional context in comments.

Comments

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.