1

I am trying to create a loop that finds the value of my input box, select the cell that has the matching value of my input box and delete its the entire row. For some reason It seems like my if condition is not working at all.

*Totalrow= my double variable for the total number of rows on my sheet *tenroxcode = my string variable for the inputbox

For i = 1 To totalrows
    If tenroxcode = Range("E" & i).Value Then
        Range("E" & i).Select
        ActiveCell.EntireRow.Delete
    End If
Next

Could someone PLEASE help me?

2 Answers 2

2

You need to loop backwards:

For i = totalrows to 1 step -1
    If tenroxcode = Range("E" & i).Value Then Rows(i).Delete
Next
Sign up to request clarification or add additional context in comments.

Comments

0

Alternate that should be significantly faster.

dim r as variant

r = application.match(tenroxcode, columns("E"), 0)
do while not iserror(r)
    rows(r).entirerow.delete
    r = application.match(tenroxcode, columns("E"), 0)
loop

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.