I am using the code below and it works, but it only runs about 30 lines and it crashes. The error is" Run-time error/automation error. Does anyone know why its crashing and how I could prevent it from crashing? If it gets an error can it just skip to the next line? The stock tickers go in column A and it pulls in the Industry into column B. All suggestions welcome. Thanks
Code:
Sub SectInd()
ActiveSheet.Activate
Set browser = CreateObject("InternetExplorer.Application")
browser.Visible = False
Dim Lastr As Integer: Lastr = ActiveSheet.Range("A6000").End(xlUp).Row
If Lastr > 2 Then
For a = 2 To Lastr
Dim Quote As String: Quote = ActiveSheet.Cells(a, 1).Value
Dim URL As String: URL = "http://finance.yahoo.com/q/in?s=" & Quote & "+Industry"
the_start:
browser.Navigate (URL)
Do
DoEvents
If Err.Number <> 0 Then
browser.Quit
Set browser = Nothing
GoTo the_start:
End If
Loop Until browser.ReadyState = 4
WebText = browser.Document.Body.InnerText
If InStr(WebText, "Sector:") > 0 Then
WebText2 = Mid(WebText, InStr(WebText, "Sector:"), 100)
TextSector = Split(WebText2, Chr(10))(1)
TextIndustry = Split(WebText2, Chr(10))(4)
End If
ActiveSheet.Cells(a, 2).Value = TextSector
ActiveSheet.Cells(a, 3).Value = TextIndustry
Next a
End If
ActiveSheet.Cells.Columns.AutoFit
End Sub