Author: Oscar Cronquist Article last updated on May 21, 2021

dynamic stock chart

This stock chart built in Excel allows you to change the date range and the chart is instantly updated.

Here is how to build this chart.

1. Create a date range

stock chart - dynamic date range

I entered "Start:" and "End:" in cell range B16:B17. The date values in cells C16 and C17 will determine when the date range begins and ends.

Back to top

2. Copy data

I found the stock price data on the yahoo finance website, here is a link to S&P 500 historical prices.

  1. Press with left mouse button on the "Get to spreadsheet" link to the get file, you can find the link below historical data.
  2. Open the geted file in Excel.
  3. Copy data from the geted file.
  4. Paste to cell A20 on your worksheet.

stock chart - historical data

The data starts from the 1950s but I can't show all data, for obvious reasons.

Back to top

3. Build dynamic named ranges

We want the chart to change depending on the start and end date in cell range B16:B17. "Named ranges" is what we are looking for, it can return a cell range of variable size.

  1. Go to "Formulas" on the ribbon.
  2. Press with left mouse button on "Named Ranges".
  3. Press with left mouse button on the "New" button.
  4. Name it "Date".
  5. Refers to:
    =INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1)):INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))

    stock chart - named ranges

  6. Press with left mouse button on "OK".
  7. Press with left mouse button on "New" button.
  8. Name it "High".
  9. Refers to:
    =INDEX(Sheet1!$C$21:$C$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810, -1)):INDEX(Sheet1!$C$21:$C$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
  10. Press with left mouse button on OK.
  11. Press with left mouse button on "New".
  12. Name it "Low".
  13. Refers to:
    =INDEX(Sheet1!$D$21:$D$810, MATCH(Sheet1!$C$16, Sheet1!$A$21:$A$810, -1)):INDEX(Sheet1!$D$21:$D$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
  14. Press with left mouse button on OK.
  15. Press with left mouse button on "New".
  16. Name it "Close".
  17. Refers to:
    =INDEX(Sheet1!$E$21:$E$810, MATCH(Sheet1!$C$16, Sheet1!$A$21:$A$810, -1)):INDEX(Sheet1!$E$21:$E$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
  18. Press with left mouse button on OK.

You have now created 4 different named ranges which are to be used in the stock chart. You can find a formula explanation later in this post. But first, let's insert a stock chart above the date range.

Back to top

4. Insert a stock chart

  1. Select cell range C21:E29, column C:E contain high, low and close values.
  2. Go to tab "Insert" on the ribbon
  3. Press with left mouse button on "Stock chart" button

stock chart

The values are in an incorrect order, they need to be reversed.

  1. Press with right mouse button on on x axis
  2. Select "Format Axis..."
  3. Enable option "Categories in reverse order"

stock chart1

Back to top

5. Change series values

It is now time to use the dynamic named ranges we created earlier. They help us quickly change the cell range we want to be shown in the chart.

  1. Press with right mouse button on on the chart.
  2. Press with left mouse button on "Select Data...".
  3. Select Series1.
  4. Press with left mouse button on the "Edit" button.
  5. Series values:
    =Sheet1!High

    (Don't forget to type the sheet name before the named range.)
    stock chart - edit series

  6. Press with left mouse button on OK.
  7. Select Series2.
  8. Press with left mouse button on the "Edit" button.
  9. Series values:
    =Sheet1!Low
  10. Press with left mouse button on OK.
  11. Select Series3.
  12. Press with left mouse button on the "Edit" button.
  13. Series values:
    =Sheet1!Close
  14. Press with left mouse button on OK.
  15. Press with left mouse button on the "Edit" button below Horizontal (Category) Axis Labels.
  16. Axis label range:
    =Sheet1!Dates

Back to top

6. Explaining the named range (Date) formula

Step 1 - Find the position of value cell C16 in cell range A21:A810

The MATCH function returns a number representing the relative position of a given value in a cell range or array.

MATCH(lookup_value, lookup_array, [match_type])

MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1)

becomes

MATCH(42248,Sheet1!$A$21:$A$810,-1)

and returns 2.

Step 2 - Calculate the first cell ref in the cell range

The INDEX function returns a value or a cell reference based on a row and column number.

INDEX(array[row_num][column_num])

INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1))

becomes

INDEX(Sheet1!$A$21:$A$810, 2)

and returns cell ref A22.

Step 3 - Find the position of value cell C17 in cell range A21:A810

The MATCH function returns a number representing the relative position of a given value in a cell range or array.

MATCH(lookup_value, lookup_array, [match_type])

MATCH(Sheet1!$C$17,Sheet1!$A$21:$A$810,-1)

becomes

MATCH(38353,Sheet1!$A$21:$A$810,-1)

and returns 130.

Step 4 - Calculate the second cell ref in the cell range

The INDEX function returns a value or a cell reference based on a row and column number.

INDEX(array[row_num][column_num])

INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))

becomes

INDEX(Sheet1!$A$21:$A$810, 130)

and returns cell ref A151.

Step 5 - Combine cell refs to a cell range

You can concatenate two cell references using the colon character to create a cell reference to a cell range.

INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1)):INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))

returns A22:A151.

Back to top

Get the Excel file


Dynamic-stock-chart.xlsx

Back to top

7. How to make the chart even more dynamic

stock chart - udf

This user defined function allows you to fetch past data for any quote on yahoo finance. You don't have to go to the yahoo finance website and copy/paste the data, this udf does it for you automatically. Just type the stock quote in cell D17 and press enter.

If you are looking for a particular company, index or commodity go to yahoo finance and use their "Quote lookup" to find the quote you are looking for.

Yes, you still need to manually adjust the y axis values on the chart every time you change the date range or stock quote unless you check out this post.

Back to top