Looping through rows on webpage table. Only works for first row

TPJoyce

New Member
Joined
Dec 28, 2013
Messages
2
Hello Still stuck on a problem. I'm trying to loop through a table on a webpage. I'm referencing my excel sheet's B1 cell. Everytime my B1 value matches the webpage tables first column value. I want to copy a specific cell from that row.


The following code only works for the first row. I suspect the issue is with my line "For z=2 to colRows1.Length - 1"


Any assistance is Greatly appreciated, Thank you!



Dim colRows1 As Object
Dim xobj3 As Object
Dim xobj4 As Object
Dim z As Long
Set colRows1 = IE.Document.getElementById("ctl05_InventoryTransactionControl_BasicDataGridInventoryTransactions").getElementsByTagName("tr")
For z = 2 To colRows1.Length - 1
Set xobj3 = colRows1.Item(z)
Set xobj4 = xobj3.getElementsByTagName("td")
If Range("B1").Text = xobj4.Item(0).innertext Then
Range("I" & (ActiveCell.Row)) = xobj4.Item(7).innertext
End If
Exit For
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
AFTERTHOUGHT:
would it be easier to do this as a Do Events kind of deal.

Dim colRows1 As Object
Dim xobj3 As Object
Dim xobj4 As Object
Dim z As Integer
Set colRows1 = IE.Document.getElementById("ctl05_InventoryTransactionControl_BasicDataGridInventoryTransactions").getElementsByTagName("tr")
z = 2
Do
Set xobj3 = colRows1.Item(z)
Set xobj4 = xobj3.getElementsByTagName("td")
If z = colRows1.Length - 1 Then
Exit Do
Else
If Range("B1").Text = xobj4.Item(0).innertext Then
Range("I" & (ActiveCell.Row)) = xobj4.Item(7).innertext
z = z + 1
DoEvents
Else
If Not Range("B1").Text = xobj4.Item(0).innertext Then
z = z + 1
DoEvents
End If
Loop
 
Upvote 0

Forum statistics

Threads
1,202,965
Messages
6,052,836
Members
444,603
Latest member
dustinjmangum

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