Help solve the error: subscript out of range

geekohi

New Member
Joined
Sep 13, 2014
Messages
3
im trying to use excel to say, when i insert stock symbols on column A, it would load me the stock prices...
when i insert till 200 rows, it seems to work
but if say, i insert 400 rows, i starting to get the error: subscript out of range.

Pls help!



my code:
______________________________________________________________________________



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
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
a picture of what im trying to do

test1.JPG
 
Upvote 0

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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