1

The below code is providing a "Loop without do error" while I have my very simple do while statement. Code runs without it, however will not loop through the 100 rows I am extracting data from.

Its clear that the issue is a result of the readystate dowhile (as code will run if I comment this out), but I am not sure of the mechanics of this working without this for IE.

Is anyone able to explain what additional(?) line of code I need to add to stop this error?

Do While i < 100

    Set ie = CreateObject("InternetExplorer.Application")

    With ie
        .Navigate URLStart
        .Visible = True
        Do While .ReadyState <> 4: DoEvents: Loop

        Set doc = ie.Document

        With doc
            LicenceNO = "whatever"
            ActiveSheet.Range("C" & i).Value = LicenceNO
            LicenceName = "whatever"
            ActiveSheet.Range("D" & i).Value = LicenceName
            BusinessAddress = "whatever"
            ActiveSheet.Range("E" & i).Value = BusinessAddress
            AATOCategory = "whatever"
            ActiveSheet.Range("F" & i).Value = AATOCategory
        End With

        i = i + 1

Loop

Thanks all!

5
  • 2
    You haven't closed your With ie block. Commented Aug 21, 2018 at 10:44
  • 2
    There is no End With to close the With ie block. Commented Aug 21, 2018 at 10:44
  • This is a good example of how uniform indentation and spacing helps highlight coding mistakes. (I fixed the indentation and now it's easier to see the issue.) [I didn't see the answer when I wrote this, but @Olly was on it already!] Commented Aug 21, 2018 at 10:56
  • unrelated, note that your loop will run until 99, not until 100. If you need to go to 100 then use <= instead of < Commented Aug 21, 2018 at 10:58
  • Right you all are, I had my end with outside my loop. I moved it back inside the loop and its now working fine! Commented Aug 21, 2018 at 11:08

1 Answer 1

1

With consistent indenting, you can see the missing End With:

Do While i < 100

    Set ie = CreateObject("InternetExplorer.Application")

    With ie
        .Navigate URLStart
        .Visible = True
        Do While .ReadyState <> 4
            DoEvents
        Loop

        Set doc = ie.Document

        With doc
            LicenceNO = "whatever"
            ActiveSheet.Range("C" & i).Value = LicenceNO
            LicenceName = "whatever"
            ActiveSheet.Range("D" & i).Value = LicenceName
            BusinessAddress = "whatever"
            ActiveSheet.Range("E" & i).Value = BusinessAddress
            AATOCategory = "whatever"
            ActiveSheet.Range("F" & i).Value = AATOCategory
        End With

        i = i + 1

    'This line missing:
    End With

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.