0

I want to handle error in VBA in IF condition For my following code the problem is that when i write On error resume Next it is handling error but continue with next statement in that is condition only, But i want to skip to next for loop

My Code:-

On Error GoTo 0
On Error Resume Next
For intRow = 2 To intLastRow

  If selenium.getText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[5]") = DOS Then

    clmn = selenium.getText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[2]")
    selenium.findElementByLinkText(clmn).Click
    FileNo = FileNo + 1
    Worksheets("Input").Cells(intRow, 9).Value = FileNo

  End If

Next intRow

1 Answer 1

1

You can tell it to jump to a maker on error:

On Error GoTo errFound
For intRow = 2 To intLastRow
    If selenium.GetText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[5]") = DOS Then
        clmn = selenium.GetText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[2]")
        selenium.findElementByLinkText(clmn).Click
        FileNo = FileNo + 1
        Worksheets("Input").Cells(intRow, 9).Value = FileNo
    End If
errFound:
Next intRow

However, I would put some if statements in there to try and handle errors rather than just jumping over them,

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.