I'm trying to write a macro. The macro is supposed to work by the user clicking on the first empty cell in column D. Then it should grab the tracking number to the left in column C. Navigate to the website. Return the delivered date into the first clicked on cell, then basically shift down one row and do the same thing without having to click again on the next row. Loop the process until you encounter the first emtpy cell in column C. This can't start at a particular cell every time because it's an on going spread sheet that's added too every week and this will start close the the bottom. For instance this week where I started was cell D2343. It's not finished code, but any suggestions would be helpful. I am fairly new to coding and extremely new to excel VBA so please bear with me. There's probably a better way to go about this than using activecell, but I'm not sure how. This
Public Sub Tracking()
Dim IE As Object
Dim ReturnValue As String
Dim ProUrl As String
Dim RowCount As Integer
Set IE = CreateObject("InternetExplorer.application")
RowCount = 0
'THIS LINE RETURN THE ERROR
Do While Not ActiveCell.Offset(-1, RowCount).Value = ""
ProUrl = "https://www.rrts.com/Tools/Tracking/Pages/MultipleResults.aspx?PROS=" & ActiveCell.Offset(-1, RowCount).Value
With IE
.Visible = False
.Navigate ProUrl
Do Until Not IE.Busy And IE.readyState = 4: DoEvents: Loop
End With
ReturnValue = Trim(IE.document.getElementsByTagName("Span")(16).innerText)
ActiveCell.Offset(, RowCount).Value = ReturnValue
RowCount = RowCount + 1
Loop
IE.Quit
Set IE = Nothing
End Sub
Any help would be appreciated. Stackoverflow has been a tremendous resource. Thank you.
I think the error may be in your Offset
method. The first argument should be the row offset, and the second argument should be the column offset. It seems like you may have that backwards.
Try changing it to:
Do While Not ActiveCell.Offset(RowCount, -1).Value = ""
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.