VBA how to stop a For Each loop

Simmo81

New Member
Joined
Sep 30, 2017
Messages
4
I dont really know what I am doing with VBA, however, I have managed to get something ALMOST working that I want to do!
Basically, I have a worksheet that has a list of gameboy games on the left hand side, and I have managed to fudge togther a macro to grab “A PRICE” from ebay, it uses the following search for example for “Darkwing Duck”
https://www.ebay.co.uk/sch/Video-Games/139973/i.html?LH_Complete=1&LH_Sold=1&_from=R40&_nkw=Darkwing Duck&_dcat=139973&rt=nc&Platform=Nintendo%2520Game%2520Boy

The macro, changes the search fine, and produces a price, however it produces the LAST price on the webpage, and I want the FIRST price, with it being the last sold item. It looks like the macro is finding ALL The prices on the page and stops at the end, I for the life of me cannot get it to stop anywhere but the end, Ive tried Exit For, but to no avail, anyone shed any light?
Below is the macro
As I said, complete novice at this, but seem to be really close to a solution.
Many thanks in advance
Simon
Sub Import_Ebay()

Dim xmlHttp As Object, lastRow As Long
Dim html As Object, ULs As Object

lastRow = Columns(“B”).Find(“*”, SearchDirection:=xlPrevious, SearchOrder:=xlByRows, LookIn:=xlValues).Row

For i = 5 To lastRow

URL = “https://www.ebay.co.uk/sch/Video-Games/139973/i.html?LH_Complete=1&LH_Sold=1&_from=R40&_nkw=” & Cells(i, 2) & “&_dcat=139973&rt=nc&Platform=Nintendo%2520Game%2520Boy”

Set xmlHttp = CreateObject(“MSXML2.ServerXMLHTTP.6.0”)
xmlHttp.Open “GET”, URL, False
xmlHttp.setRequestHeader “Content-Type”, “text/xml”
xmlHttp.send
Set html = CreateObject(“htmlfile”)
html.body.innerHTML = xmlHttp.responseText
Set ULs = html.getElementsByTagName(“ul”)
For Each UL In ULs
If UL.className Like “lvprices *” Then
For Each hLi In UL.Children
If hLi.className = “lvprice prc” Then ActiveSheet.Cells(i, 7).Value = hLi.innerText
Next hLi
End If
Next UL
Next
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
From that link you can see various prices for Darkwing Duck, the most recent being £1.85, and the last price on the page is for a collection of games at £119.99, my sheet returns this £119.99, I realise I will struggle to omit these sort of results, but want the most recent, ie the first result to be the one that is returned in my worksheet.

Many thanks in advance once again
 
Upvote 0
Whilst the macro is working, I even see the £1.86 that I want as my result, before it changes, so I cant be far away from getting it right!!!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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