crazyeyeschase
Board Regular
- Joined
- May 6, 2014
- Messages
- 104
- Office Version
- 365
- Platform
- Windows
I am working on a set of macros that can search given websites with similar source code to find the price of a product. (each websites source code differs slightly so the macros will also differ slightly)
In the long run ill then run something that will tell me what vendor to purchase each product from based on their price.
The issue I am running into is I need to loop thru an entire column "A" until the cell is empty as more cells may be added in the future. I will then need to input the answer into the adjacent cell in column B.
This code currently does everything i need for now but the looping.
In the long run ill then run something that will tell me what vendor to purchase each product from based on their price.
The issue I am running into is I need to loop thru an entire column "A" until the cell is empty as more cells may be added in the future. I will then need to input the answer into the adjacent cell in column B.
This code currently does everything i need for now but the looping.
VBA Code:
Sub Klempfs()
Dim IE As Object
Dim Price As String
Dim rRng As Range
Dim rCell As Range
Set IE = CreateObject("internetexplorer.application")
Set rRng = Range("A1")
With IE
.Navigate ("http://www.klempfsbritishparts.com/search?q=" & rRng)
.Visible = False
End With
Do While IE.readystate <> 4: Wait 5: Loop
DoEvents
For Each rCell In rRng.Cells
On Error Resume Next
Price = IE.document.getElementsByClassName("price")(0).innertext
Cells(1, "B").Value = Price
If Err.Number = 91 Then
Cells(1, "B").Value = "N/A"
End If
Next rCell
MsgBox "end"
End Sub
Private Sub Wait(ByVal nSec As Long)
nSec = nSec + Timer
While nSec > Timer
DoEvents
Wend
End Sub