I'm relatively new to VBA, but have been increasing my exposure over time. Along time ago while first learning about web queries I stumbled upon this code I believe I got from Chip Pearson (per the note left behind). He has a site with a lot of downloads and help available if you care to Google him. Anyway found this code that wasn't useful to me at the time, but saved it and now suddenly I have use for it. Essentially you can have a list of stock symbols/tickers, input a date range, hit the control button and it will retrieve historical stock prices from yahoo finance and place each set of historical price data into a new tab/worksheet and re-title the worksheet with the ticker symbol. I modified the sheet a bit such that I pull data from the tabs and perform other processes with the data download.
What I am stuck with: I'd like to add sparkline cells corresponding to the row/ticker that will refresh each time I download new data. See my attachment and hit the retrieve button, you will notice that the sparklines disappear. I believe this is happening because the VBA code deletes the sheets then creates a new one and labels it with the ticker symbol, however the sheet data that the sparklines were referring to is no longer there (despite being named the same as the previous location). I noticed this when I have the editor project pane open and it displays the 'name' in parentheses , but the sheet numbers change with each successive button click. I'm not clever enough yet to pick apart the wonderful code I lifted; Is there a way that when you refresh the data download it just overwrites the same sheet, so that the spark line references reflect the 'new' data? Is there another way to write the code to get to my end goal?
Additional challenge! (read on)
The list of tickers I want to retrieve may change dramatically not only in quantity but also the names, the date range I would be interested may also change significantly. That said I'd like to some how figure out a way/formula to input such that the sparkline array reference will change according to the ticker/tab name and the column array dimension. Ideally I'd like to copy the first row/set of formulas (under the brown column headings) drag and paste all the way down to the last ticker. I've played a bit with the range selection portal that pops up when creating the sparkline and some formulas (i.e INDIRECT) just don't work there.
Bookmarks