Yahoo Finance data

overbet

Board Regular
Joined
Jul 9, 2010
Messages
63
Office Version
  1. 2010
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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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