+ Reply to Thread
Results 1 to 5 of 5

Thread: subscript out of range: reading cell values into vb array

  1. #1
    Registered User
    Join Date
    03-30-2011
    Location
    NY, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    subscript out of range: reading cell values into vb array

    subscript out of range: reading cell values into vb array

    folks (domski, teylyn, whizbang),

    a little while ago i took your code to solve the following:
    ....can i address the cells selected when holding the CTRL key?...

    worked great, so i took another step; this time i have a named range called "master_list" which holds a bunch of tickers:

    here's a sample:
    ACAS
    HHC
    RELL
    hs
    prgo
    mwiv
    aapl
    ctsh
    nsc
    fti
    esrx
    cvx
    scl
    npk
    lll

    and i added a button on the same worksheet as holds the named range. press the button and it calls a routine to read the named range, build a vb array, and iterate thru the array to take each ticker and call a routine to go to yahoo and get the price.
    when i execute, i get ...subscript out of range... and reading the assorted help still doesn't seem to shed any light.

    here's the code
    Sub collectTickers()
    
    Dim ticker As String
    Dim tickerCount As Integer
    Dim tickers() As String
    Dim iCount As Integer
    Dim jCount As Integer
    
    tickerCount = Range("master_list").Rows.CountA
    MsgBox tickerCount
    
    ReDim tickers(1 To tickerCount)
    
    ' fill the array
    For iCount = 1 To tickerCount
        tickers(iCount) = Range("master_list_symbol")(iCount)
        MsgBox tickers(iCount, 1)
    Next iCount
    
    ' process tickers
    For jCount = 1 To UBound(tickers)
        ticker = tickers(jCount)
        Call DoTheExport1(cell:=ticker)
    Next jCount
    
    End Sub
    i think the code seems in the spirit of what you folks helped me with before, but of course i could have messed up.

    thanks for taking a look,
    ron
    Last edited by rny1ef; 07-03-2011 at 10:39 AM.

  2. #2
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,300

    Re: subscript out of range: reading cell values into vb array

    Hi Ron,

    Please click on the green Edit button below your message and then on the "Go Advanced". Select all the code and click on the "#" Icon above the advanced message area. This will put code tags around your code and look like this"
    tickerCount = Range("master_list").Rows.CountA
    In your message you didn't put the "/" character in the last code tag so it didn't work.

    Also look at the above line of your code to see if it really gives you the number of cells in master_list.
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  3. #3
    Registered User
    Join Date
    03-30-2011
    Location
    NY, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: subscript out of range: reading cell values into vb array

    marvinp,

    ok, neat -- the business with the advanced & # for code tags. i'll try the / after end sub. looks like i have plenty to learn

    thanks,
    ron

  4. #4
    Registered User
    Join Date
    03-30-2011
    Location
    NY, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: subscript out of range: reading cell values into vb array

    marvinp,

    ok, put / after end sub and it gave a complie error.
    did i misunderstand totally what you were trying to tell me?

    ron

  5. #5
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,300

    Re: subscript out of range: reading cell values into vb array

    Hi,
    The "/" was only in the message part.
    I was thinking the code of:
    tickerCount = Range("master_list").Rows.CountA
    wasn't giving you back what you expected.

    Set a breakpoint in your code and step through it and hover your mouse over the variables to insure they are what you expect.
    Read the below link to see all you can do while debugging.
    http://www.cpearson.com/excel/Debug.htm
    One test is worth a thousand opinions.
    Click the * below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0