Hello, I need help with some code. What I have is an extremely simple worksheet. Column A has Stock Tickers, my Code Goes out and grabs the Prices for the Tickers, and I want to put the Price for the Stock in the adjoining Column B of the Worksheet. However, right now the values return fine, but go across columns instead of down rows.
Code:
Sub GetStockQuotes()
Dim DataRange As Range
Dim Cell As Range
Dim LastRow As Long
Dim StartRow As Long
Dim Col As Long
Dim Ticker As String
Dim StockPrice As Long
StartRow = 1
Col = 1
LastRow = FindLastRow(Col)
Set DataRange = Range(Cells(StartRow, Col), Cells(LastRow, Col))
For Each Cell In DataRange
Ticker = Cell.Value
ConnectStr = "URL;http://finance.yahoo.com/d/quotes.csv?s=" & Ticker & "&f=l1"
With ActiveSheet.QueryTables.Add(Connection:=ConnectStr, Destination:=Range("B65536").End(xlUp))
.Name = "StockPrices_" & StSymbol
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.WebSelectionType = xlSpecifiedTables
.WebTables = "20"
.WebFormatting = xlWebFormattingNone
.WebSingleBlockTextImport = False
.Refresh
End With
Next Cell
End Sub
Function FindLastRow(ByVal Col As Integer) As Long
FindLastRow = Cells(Rows.Count, Col).End(xlUp).Row
End Function
Last edited by a moderator: