
Originally Posted by
Norie
Where in the code do you get the error?
the thing I dont quite understand is, I am not getting any errors in my code.
The code does function as expected when say, I insert roughly 200 stock code on column A.
If I insert > 300-400, then it runs and just says that: subscript out of range (without pointing to me, where in the code I get the error)
Im trying to make this stock data loader applicable to say, thousands of stocks.
The line of code used for the loading process (when press on "load button"), its sheet19 (stocks)
Sub loaddata()
Dim W As Worksheet: Set W = ActiveSheet
Dim i As Integer
Dim Last As Integer
Worksheets("Stocks").Activate
Last = W.Range("A6000").End(xlUp).Row
If Last = 1 Then Exit Sub
Dim Symbols As String
For i = 2 To Last
Symbols = Symbols & W.Range("A" & i).Value & "+"
Next i
Symbols = Left(Symbols, Len(Symbols) - 1)
Dim URL As String: URL = "http://finance.yahoo.com/d/quotes.csv?s=" & Symbols & "&f=snd1ohgl1v"
Dim X As New WinHttpRequest
X.Open "GET", URL, False
X.send
Dim Resp As String: Resp = X.responseText
Dim Lines As Variant: Lines = Split(Resp, vbCrLf)
Dim sLine As String
Dim Values As Variant
For i = 0 To UBound(Lines)
sLine = Lines(i)
If InStr(sLine, ",") > 0 Then
Values = Split(sLine, ",")
W.Cells(i + 2, 2).Value = Replace(Split(Split(sLine, Chr(34) & "," & Chr(34))(1), Chr(34) & ",")(0), Chr(34), "")
W.Cells(i + 2, 3).Value = Replace(Values(UBound(Values) - 5), Chr(34), "")
W.Cells(i + 2, 3).NumberFormat = "yyyy-mm-dd;@"
W.Cells(i + 2, 4).Value = Values(UBound(Values) - 4)
W.Cells(i + 2, 5).Value = Values(UBound(Values) - 3)
W.Cells(i + 2, 6).Value = Values(UBound(Values) - 2)
W.Cells(i + 2, 7).Value = Values(UBound(Values) - 1)
W.Cells(i + 2, 8).Value = Values(UBound(Values))
End If
Next i
W.Cells.Columns.AutoFit
End Sub
Bookmarks