For loop to find values on a webpage from label array returning 0

JoeDalen

New Member
Joined
Sep 4, 2014
Messages
1
Hi All,

I'm hoping you could help me with an issue I've been having while trying to search for values from a label array on a webpage. What I'm trying to do is find a value from a label on a userform on a webpage and then have it display the results back on the userform. The loop seems to work great the first time however, when it goes through the loop the second time it can never find the 2nd value. I have searched for these values individually outside the loop and it finds them with no issue, I'm not sure why it can't find them from within the loop. Whenever I step through the code (F8) the "findText" line is returning a zero and then I get a runtime 5 error "invalide procedure call or argument" on the next line (txt = Mid(iedoc.body.innerHTML, findText). I am a programming novice so please bare with me if I need a more in depth explanation. Below is my code for running through the loop on the webpage. I have to block out the URL's for security reasons.

Value1 = Left(lblarray(I).Caption, 3)
Value2 = Left(lblarray(I).Caption, 2)
For I = LBound(lblarray) To UBound(lblarray)

'Find if rule/Calc or data field
If Value1 = "RU_" Or Value2 = "C_" Then
ie.navigate "I can't include this"
Do Until ie.readyState = READYSTATE_COMPLETE
Loop
Else
ie.navigate "I can't include this"
Do Until ie.readyState = READYSTATE_COMPLETE
Loop
End If

ToFind = lblarray(I).Caption
tof = Len(ToFind)
findText = InStr(1, iedoc.body.innerHTML, ToFind, vbTextCompare)
txt = Mid(iedoc.body.innerHTML, findText)

If findText > 0 Then
Dim x As Long, j As Long, msg As String
If Value1 = "RU_" Then
x = 7
Else
x = 4
End If
For j = 0 To x - 1
lblarray(I).Caption = Split(txt)(j) & " "
Next j
Else
MsgBox "The text dosen't exist"
End If
Next I
End If

Thank you to everyone who takes the time to read through this!!!

-Joe
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,191,081
Messages
5,984,518
Members
439,894
Latest member
Amba1006

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
Top