I think something like this will work for you, assuming you want the downloaded CSV data to be split (via TextToColumns) into separate columns. In this example, the ticker symbol list starts in row 5. I download the data in sets of 50 ticker symbols, since I found that Yahoo chokes (or cuts you off) if you try to download data for like 200 tickers at once. The QueryTable delete at the end removes the data connection (otherwise you end up with an ever-growing list of open data connections):
Sub Download Stock Data()
'
' Download stock data CSV table for list of tickers
'
Dim LastRow As Integer, StartRow As Integer, StopRow As Integer, rowcounter As Integer
Dim AllTickers As String, URLString1 As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
LastRow = Worksheets("Data2").Cells(Rows.Count, "A").End(xlUp).Row
StartRow = 5
StopRow = Application.WorksheetFunction.Min(StartRow + 49, LastRow)
Do While StartRow < LastRow
' Assemble StockTickers string containing all tickers, comma separated
AllTickers = ""
For rowcounter = StartRow To StopRow
AllTickers = AllTickers & Worksheets("Data2").Range("$A$" & rowcounter) & ","
Next rowcounter
' Download basic data for all tickers
URLString1 = "URL;http://download.finance.yahoo.com/d/quotes.csv?s=" + AllTickers + "&f=sl1va2f6t8r5rr6r7j2s7enqd1&e=.csv"
With Worksheets("Data2").QueryTables.Add(Connection:=URLString1, Destination:=Range("$B$" & StartRow))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.Refresh
End With
StartRow = StopRow + 1
StopRow = Application.WorksheetFunction.Min(StartRow + 49, LastRow)
Loop
Worksheets("Data2").Range("$B$5:$B$" & LastRow).TextToColumns Destination:=Range("$B$5"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Comma:=True
Worksheets("Data2").QueryTables(1).Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Also, forgot to mention: If you don't want to expand the downloaded CSV data, just delete the TextToColumns line (7th line from the bottom)
Bookmarks