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
i think the code seems in the spirit of what you folks helped me with before, but of course i could have messed up.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
thanks for taking a look,
ron
Last edited by rny1ef; 07-03-2011 at 10:39 AM.
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"
In your message you didn't put the "/" character in the last code tag so it didn't work.tickerCount = Range("master_list").Rows.CountA
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.
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
marvinp,
ok, put / after end sub and it gave a complie error.
did i misunderstand totally what you were trying to tell me?
ron
Hi,
The "/" was only in the message part.
I was thinking the code of:
wasn't giving you back what you expected.tickerCount = Range("master_list").Rows.CountA
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks