Help make this code loop thoruhg properly?

30136353

Board Regular
Joined
Aug 14, 2019
Messages
90
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

rlv01

Well-known Member
Joined
May 16, 2017
Messages
791
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,130
Messages
5,640,301
Members
417,135
Latest member
zeusmining

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
Top