Help make this code loop thoruhg properly?

30136353

Board Regular
Joined
Aug 14, 2019
Messages
105
Hi Guys,

I have the below code which currently opens up a postcode website, searches an address ( made up from cells from row 2, column 4 + 5 ), then returns the search result into row 2 column 7... This works fine but doesn't seemt o loop properly, all the rows in the workbook get the same first post code pasted into every cell down column 7, anyone any idea? Thanks.

VBA Code:
Dim i As Long
i = 2

Do While Not IsEmpty(Cells(i, 4).Value)

    IE.document.getElementsByName("val")(0).Value = Cells(i, 4) & " " & Cells(i, 5) & ", Edinburgh"
IE.document.forms(0).submit

Dim postcodeDiv As Object
Dim parts As Variant, Postcode As String
Do
Set postcodeDiv = IE.document.getElementsByClassName("postcode")(0)
DoEvents
Loop While postcodeDiv Is Nothing
parts = Split(postcodeDiv.innerText, "Postcode: ")
Postcode = Split(parts(1), vbCrLf)(0)

Cells(i, 7).Value = Postcode
i = i + 1
Loop
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Probably because for whatever reason, Postcode is always evaluating to the same value. Whether this:
VBA Code:
        parts = Split(postcodeDiv.innerText, "Postcode: ")
has anything to do with that, I cannot say; but it's an error since the delimiter for the Split function must be a single character , not a string like "Postcode: " . Use the VBE debugger to single-step (F8) through the code to see where it is going off the rails.
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top