I am using a do until loop to bring in multiple webpages using a variable. After a webpage is brought into a temporary spreadsheet, I am searching for a specific phrase ("Last 3 years"). If that phrase is not present, I want it to delete that temp sheet and the loop to the next page. If it is there, then I want it to continue to the next search ("Fund Report Card") and then the rest of the code. However, when I use the following code, my error handling only works once and then I get a "run time error 91" on the second time it can't find the first phrase. How can I reset the error handling so it doesn't get hung up after the second time it errors out?
Code:
Sub getFundGrades2()
cNum = 1
Do Until cNum = 100000
On Error GoTo EndOfSection
Sheets.Add.Name = "DataTemp"
Sheets("DataTemp").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.testingweb.com/securityreport.aspx?id=" & cNum, Destination:= _
Range("$B$2"))
.Name = "securityreport.aspx?id=" & cNum
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Cells.Find(What:="Last 3 Years", After:=[B1], LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Cells.Find(What:="Fund Report Card", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Offset(3, 0).Select
fgSymbol = Left(Selection, WorksheetFunction.Find("-", Selection) - 2)
fgRow = WorksheetFunction.CountA(Sheets("FG_Database").Range("FG_Count")) + 3
Sheets("FG_Database").Cells(fgRow, 2) = fgSymbol
Sheets("FG_Database").Cells(fgRow, 3) = cNum
EndOfSection:
On Error GoTo 0
cNum = cNum + 1
Worksheets("DataTemp").Select
Application.DisplayAlerts = False
Worksheets("DataTemp").Delete
Application.DisplayAlerts = True
Application.Goto Reference:=Worksheets("FG_Database").Cells(fgRow, 2), Scroll:=False
Loop
End Sub