1

I am trying to delete complete row which contain the value "THD" in first cell. The content could look like "THD_C_L10.0W5.0H15.0P7.5" but THD is always there.

I tried it with following loop:

For i = 1 To ActiveSheet.UsedRange.Rows.Count
    If InStr(1, LCase(Tabelle2.Cells(i, 1)), "THD") <> 0 Then
        Rows(i).EntireRow.Delete
    End If
Next

But unfortunately its not working. Any ideas?

1 Answer 1

2

When you delete rows you have to start your loop from last element and direct into first. Therefore, instead of:

For i = 1 To ActiveSheet.UsedRange.Rows.Count

you should have something like this:

For i = ActiveSheet.UsedRange.Rows.Count to 1 Step -1

One additional tip which shouldn't affect your current sub- InStr has additional parameter which you could use. This line is equivalent to yours one:

If InStr(1, Tabelle2.Cells(i, 1), "THD",vbTextCompare) <> 0 Then
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.