I have a code that runs perfectly when stepping through, but it doesn't run completely when ran as whole. There are no errors. The code searches through HTML tags and scans for a keyword, if that keyword is found within an HTML cell, the whole cell is outputted to an Excel cell. I am looking for a keyword that appears 3 times on a webpage. When I debug and step through, all 3 instances of the keyword are found, and the cell it is in populates cells A1:C1 in Excel. However, when the code is ran as a whole, only the first two instances are found. Can anyone tell me why that is? My guess is the IF statement is not triggered for the last keyword for some reason... I will include the HTML body and my VBA code.
<HTML>
<HEAD>
<META NAME="name" CONTENT="sldfkjsd">
<TITLE>Title</TITLE>
<P>
<TABLE BORDER=3 CELLPADDING=6 CELLSPACING=3>
<TR>
<TD>
<PRE>
AAAA AAAA AAAA AAA AAA AAAA AAA AAAA AAAA AAA
BBBBb BBBBB BBBBB BBBBB BBBBBBBBBBBBBB B
keyword
CCCCCCCcc CCCCCCCCCC CCCCCCCCCCCC DDDDDDDD
</PRE>
</TD>
</TR>
<TR>
<TD>
<PRE>
AAAA AAAA AAAA AAA AAA AAAA AAA AAAA AAAA AAA
BBBBb BBBBB BBBBB BBBBB BBBBBBBBBBBBBB B
keyword
CCCCCCCcc CCCCCCCCCC CCCCCCCCCCCC DDDDDDDD
</PRE>
</TD>
</TR>
<TR>
<TD>
<PRE>
AAAA AAAA AAAA AAA AAA AAAA AAA AAAA AAAA AAA
BBBBb BBBBB BBBBB BBBBB BBBBBBBBBBBBBB B
keyword
CCCCCCCcc CCCCCCCCCC CCCCCCCCCCCC DDDDDDDD
</PRE>
</TD>
</TR>
<NEXT></NEXT>
</TABLE>
Sub subFindScrollIE()
'Set Variables
Dim boolFound As Boolean
Dim strTemp() As Variant, txt As String
Dim strOutput As String
Dim tbl As HTMLTable, tables As IHTMLElementCollection
Dim tr As HTMLTableRow, r As Integer, i As Integer
Dim tRows As IHTMLElementCollection
Dim ie As InternetExplorer
'Delete Rows and Select A1
Rows("1:100").Delete
ActiveSheet.Range("A1").Select
Set ie = New InternetExplorer
'Show Webpage (optional)
'ie.Visible = True
Dim dateToday As String
'Get Today's date in yyyymmmdd to input into URL for most today's alert page
dateToday = Format((Now), "yyyymmdd")
'Navigate to Desired URL with today's date
ie.Navigate "URL" & dateToday & ".html"
'Input Keywords
strTemp = Array("Keyword")
'Wait for IE page to finish loading
Do Until ie.ReadyState = READYSTATE_COMPLETE Or ie.ReadyState = READYSTATE_INTERACTIVE
'DoEvents
Loop
'Declare rows
Set allrows = ie.Document.body.getElementsByTagName("tr")
' loop through rows
For Each trow In allrows
Set tcell = trow.Cells
' loop through cells
For r = 0 To (tcell.Length - 1)
Set td = tcell(r)
' loop through search text
For i = 0 To UBound(strTemp)
' search row for string
txt = LCase(td.innerHTML)
If (InStr(txt, LCase(strTemp(i))) > 0) Then
Application.PrintCommunication = True
' search string found. create output html table
'strOutput = strOutput & tRows(r).outerHTML & vbCrLf
strOutput = tcell(r).innerHTML
'Output string to new workbook
ActiveCell.Value = strOutput
'Move one cell to the right for next possible match to be pasted
ActiveCell.Offset(0, 1).Select
'Reset string (just in case, not needed)
Debug.Print strOutput
strOutput = ""
End If
Next i
Next r
Next trow
End Sub