Create a dynamic stock chart using a web query and a drop down list in excel
In this blog post I´ll show you how to update a stock chart in excel using a drop down menu and a web query connection.
- Create list of companies and corresponding tickers
- Create a dynamic range
- Create a drop down list
- Calculate dates
- Create a web query
- Create a macro to refresh web query and automate "text to columns"
- Create a stock chart
- Create a button
Here is a picture of the final result:
At the end of this post is an attached excel tutorial file.
Create list of companies and corresponding tickers
In this tutorial I have two sheets, Overview and Data. On sheet Overview I created a small list of companies and corresponding ticker. You can search tickers at http://finance.yahoo.com/
Create a dynamic range
As I add new companies and tickers to the list I want the drop down list automatically updated. To accomplish this I need to create a dynamic named range.
- Click tab "Formulas"
- Click "Named ranges"
- Click "New"
- Name your range (formula in this tutorial).
I named it "Dynrange". - Type in "Refers to:" =OFFSET(Overview!$B$3, 0, 0, COUNTA(Overview!$B:$B)-1, 1)
- Click OK!
Create a drop down list
- Select cell E3
- Click "Data" tab
- Click "Data validation"
- Click "Data validation..."

- Select Allow: List
- Type in "Source:" =Dynrange
- Click OK!
Calculate dates
To download the latest three months of historical data we need to calculate the the date three months back.
I did this calculation on sheet "Data". The formulas use the current date today automatically.
Cell H1 matches the corresponding ticker to the selected company in the drop down list.
See formula details on the attached file at the bottom of this post.
Create a web query
- Click "Data" tab
- Click "From web"
- Paste this into address field:http://table.finance.yahoo.com/table.csv?a=["fm","fm"]&b=["fd","fd"]&c=["fy","fy"]&d=["tm","tm"]&e=["td","td"]&f=["ty","ty"]&s=["ticker", "ticker"]&y=0&g=d&ignore=.csv
- Click "Go"
- Click "Import"
- Select cell "A10" on sheet "Data"
- Click OK

- Select cell E3 (fm) . Enable "Use this value/reference for future refreshes". Click OK.
- Select cell E4 (fd) . Enable "Use this value/reference for future refreshes". Click OK.
- Select cell E2 (fy) . Enable "Use this value/reference for future refreshes". Click OK.
- Select cell B3 (tm) . Enable "Use this value/reference for future refreshes". Click OK.
- Select cell B4 (td) . Enable "Use this value/reference for future refreshes". Click OK.
- Select cell B2 (ty) . Enable "Use this value/reference for future refreshes". Click OK.
- Select cell H1 (ticker) . Enable "Use this value/reference for future refreshes". Click OK.
VBA code to refresh web query and automate "text to columns".
- Click "Developer" tab
How to show the Developer tab or run in developer mode - Click "Visual Basic"
- Create a "Module" for your workbook
How to Copy Excel VBA Code to a Regular Module - Copy this vba code into module:
Sub Refreshwebq()
Set qryTableStocks = ThisWorkbook.Worksheets("Data").QueryTables(1)
With qryTableStocks
.BackgroundQuery = False
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("Data").Select
Range("A10").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
ActiveWorkbook.Connections("Connection").Refresh
Sheets("Data").Select
Range("A10").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.TextToColumns Destination:=Range("A10"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1)), TrailingMinusNumbers:=True
Sheets("Overview").Select
End Sub
Create a stock chart
- Select High, Low and Close columns on sheet "Data"
- Click "Insert" tab
- Click "Other charts"
- Click High-Low-Close stock chart
- Cut and paste stock chart to sheet "Overview"
- Right click on x-axis values
- Click "Select data"
- Click "Edit" in Horizontal (Category) axis labels
- Select Dates on sheet "Data", =Data!$A$11:$A$71
- Click OK!
- Click OK!
- Right click on x-axis values
- Click "Format axis"
- Click Axis Options
- Click Axis Type: Text axis
- Click Categories in reverse order
- Click Vertical axis crosses: At maximum category

- Click Close
Create a button and assign macro Refreshwebq()
How to Run an Excel Macro With a Worksheet Button
Download excel tutorial file
dynamic stock chart using web query.xls
(Excel 97-2003 Workbook *.xls)
Related posts:
Excel charts: Use dynamic ranges to add new values to both chart and drop down list
Learn how to create a stock chart in excel
Dynamic stock chart in excel – Add date ranges




















Wonderful site. Plenty of helpful info here. I am sending it to some buddies ans also sharing in delicious. And of course, thanks for your effort!