0

With the code below, i'm able to get current key statistics from Yahoo for multiple tickers. Do you know if it's possible to change the code below in order to get historical data ? For instance, the statistics registered for a ticker 3 years ago ?

Many thanks in advance for your answers and you for your help

Sub KeyStat()

For i = 2 To Sheets(1).Cells(1, 1).End(xlToRight).Column

ticker = Sheets(1).Cells(1, i)
qurl = "https://finance.yahoo.com/quote/" & ticker & "/key-statistics?p=" & ticker & ""

Sheets(2).Select
Sheets(2).Cells.Clear

    With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets(2).Range("A1"))
        .BackgroundQuery = True
        .TablesOnlyFromHTML = False
        .Refresh BackgroundQuery:=False
        .SaveData = True
    End With

Sheets(2).Range("B3:B69").Copy
Sheets(1).Select
Cells(2, i).Select
ActiveSheet.Paste
CutCopyMode = False

Next i


End Sub 
mollieda
  • 69
  • 6
  • 1
    What is the value of `ticker`? – BigBen Oct 23 '19 at 23:03
  • 1
    Works for me with a valid ticker symbol – Tim Williams Oct 23 '19 at 23:33
  • You might benefit from reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). – Pᴇʜ Oct 24 '19 at 06:19
  • The above code is useful but is limited to the use of 50 tickers. If I use more than 50 tickers, I am confronted with bugs. Is there a possibility to modify this code to load in mass the statistical data of several hundred tickers? Many thanks in advance for your help. – mollieda Dec 03 '19 at 21:06

0 Answers0