Results 1 to 14 of 14

Subscript out of range - help!

Threaded View

  1. #1
    Registered User
    Join Date
    09-13-2014
    Location
    australia
    MS-Off Ver
    2013
    Posts
    11

    Subscript out of range - help!

    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.

    test1.JPG

    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
    Last edited by Leith Ross; 09-14-2014 at 12:11 AM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Subscript Out of Range
    By blyzzard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2013, 05:25 PM
  2. what does subscript out of range mean?
    By amartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2013, 01:55 AM
  3. Subscript out of range error while populating array from range.
    By Aussiexile in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2010, 02:22 AM
  4. Subscript out of range error when trying to select a range
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2010, 07:57 PM
  5. Subscript out of range?
    By Iamkar33m in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2007, 10:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1