jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
If one of the ret(1), ret(2), ret(3) is not found it skips it, but it pastes the next one in that row, rather than skipping; any ideas how to alter the code to achieve this please?
Thanks.
Thanks.
Code:
Option Explicit
Sub Get_Prices()
Dim Lastrow As Long
Dim LastRow2 As Long
Dim x As Long
Dim urls As Variant
Dim Prices As Variant
'Create sheet
Application.ScreenUpdating = False
Lastrow = Sheets("Comparison").Columns("P").Find("*", , xlValues, , xlRows, xlPrevious).Row
urls = Sheets("Comparison").Range("P21:P" & Lastrow).Value
For x = LBound(urls) To UBound(urls)
Prices = getprices(urls(x, 1))
Sheets("Comparison").Cells(Sheets("Comparison").Rows.Count, 7).End(xlUp).Offset(1).Resize(, UBound(Prices)).Value2 = Prices
Next x
End Sub
Private Function getprices(ByVal URL As String) As Variant
Dim source As Object
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim ret(1 To 3) As String
With http
.Open "GET", URL, False
.send
html.body.innerHTML = .responseText
End With
On Error Resume Next
ret(1) = html.querySelector(".price-details--wrapper .value").innerText
ret(2) = html.querySelector(".price-per-quantity-weight .value").innerText
ret(3) = html.querySelector(".price-per-quantity-weight .weight").innerText
Private Function getprices(ByVal URL As String) As Variant
Dim source As Object
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim ret(1 To 3) As String
With http
.Open "GET", URL, False
.send
html.body.innerHTML = .responseText
End With
On Error Resume Next
ret(1) = html.querySelector(".price-details--wrapper .value").innerText
ret(2) = html.querySelector(".price-per-quantity-weight .value").innerText
ret(3) = html.querySelector(".price-per-quantity-weight .weight").innerText
getprices = ret
End Function
getprices = ret
End Function