Excel Stock History Function: What It Is and How to Use It
Excel does not have a built-in STOCKHISTORY function in all versions, but Microsoft 365 subscribers with certain plans can use the STOCKHISTORY function to retrieve historical stock prices directly in a spreadsheet. The function pulls data from Microsoft's financial data provider and returns a dynamic array of dates and closing prices (or other fields) for a specified stock symbol and date range. If you are using Excel 2019, Excel 2021, or a non-subscription version, STOCKHISTORY is not available, and you will need to use alternative methods such as Power Query with a web data source or a third-party add-in.
Background: What Is STOCKHISTORY?
STOCKHISTORY is one of Excel's linked data types functions, introduced alongside the Stocks data type in 2019 for Microsoft 365 subscribers. It allows you to write a formula like =STOCKHISTORY("MSFT", "2024-01-01", "2024-12-31") and get a spilled range of historical closing prices for Microsoft stock over that period. The function is part of Excel's effort to bring external data into the grid without manual imports. It relies on an internet connection and Microsoft's financial data service, which sources information from Refinitiv (now part of LSEG). The data is delayed and intended for informational purposes, not for real-time trading decisions. STOCKHISTORY is available in Excel for Microsoft 365 on Windows, Mac, and the web, but not in Excel for iPad or iPhone at the time of writing.
How STOCKHISTORY Works: Syntax and Arguments
The function has the following syntax:
=STOCKHISTORY(stock, start_date, [end_date], [interval], [headers], [property0], [property1], ...)
- stock (required): A ticker symbol or a reference to a cell containing one, such as "AAPL" or "MSFT". You can also use a Stocks data type cell.
- start_date (required): The earliest date for which you want data. Use a date value or a cell reference.
- end_date (optional): The latest date. If omitted, only the start_date is used (a single day).
- interval (optional): "Daily" (default), "Weekly", or "Monthly".
- headers (optional): 0 for no headers, 1 for headers (default is 1).
- property0, property1, ... (optional): Columns to return. 0 = Date, 1 = Close, 2 = Open, 3 = High, 4 = Low, 5 = Volume. If omitted, Date and Close are returned.
For example, =STOCKHISTORY("IBM", "2024-01-01", "2024-03-31", 0, 1, 0, 1, 5) returns daily data with headers for Date, Close, and Volume for IBM from January 1 to March 31, 2024.
How to Use STOCKHISTORY: Step by Step
- Ensure you have a Microsoft 365 subscription and are signed in with an account that has a license for Excel.
- Open a new or existing workbook and click on an empty cell where you want the data to start.
- Type the STOCKHISTORY formula with your desired arguments. For a quick test, enter
=STOCKHISTORY("MSFT", TODAY()-30, TODAY())to get the last 30 days of closing prices for Microsoft. - Press Enter. Excel will spill the results into adjacent cells. If you see a #SPILL! error, make sure there is enough empty space.
- Format the date column as dates and the price column as currency or numbers with decimals as needed.
- To change the data, edit the formula in the original cell; the spilled range updates automatically.
Note that STOCKHISTORY returns a dynamic array, so you cannot edit individual cells in the spilled range. To work with the data further, you can copy and paste as values, or reference the spilled range in other formulas.
Common Problems and Limitations
Users often encounter issues with STOCKHISTORY. Here are some common ones and how to address them:
- #VALUE! error: Often caused by an invalid ticker symbol or a date that is not recognized. Check that the symbol is correct and the dates are valid Excel dates.
- #BUSY! error: The function is still retrieving data. Wait a moment or press F9 to recalculate.
- #CONNECT! error: Indicates a problem with the data connection. Ensure you have an internet connection and that the stock symbol is valid.
- #BLOCKED! error: The function may be blocked by your organization's policy or by Excel's security settings. Check with your administrator.
- #FIELD! error: Occurs when an invalid property number is used. Valid property numbers are 0 to 5.
- No data for certain dates: Stock markets are closed on weekends and holidays, so STOCKHISTORY returns only trading days. If you request a date range with no trading days, you may get an error or empty results.
- Delayed data: The data is not real-time; it may be delayed by up to 15 minutes or more. Do not use it for live trading.
- Availability: STOCKHISTORY is not available in Excel 2019, 2021, or older versions, nor in Excel for iPad or iPhone. It also requires a Microsoft 365 subscription that includes linked data types.
Alternatives to STOCKHISTORY
If STOCKHISTORY is not available to you, there are several ways to get historical stock data into Excel:
- Power Query: Use the "From Web" connector to pull data from financial websites that offer CSV downloads. This method requires some setup but works in most Excel versions.
- Stocks data type: If you have Microsoft 365, you can use the Stocks data type to get current information, but it does not provide historical time series directly. You can combine it with other functions.
- Third-party add-ins: Several vendors offer Excel add-ins that provide historical stock data, often with more features and real-time updates for a fee.
- Manual import: Download CSV files from financial sites and import them into Excel. This is free but not automated.
- Google Sheets: Google Sheets has a GOOGLEFINANCE function that provides historical stock data, which you can then export to Excel.
Each alternative has trade-offs in terms of ease of use, automation, and cost. Power Query is the most robust free method for Excel users without STOCKHISTORY.
Frequently Asked Questions
Is STOCKHISTORY free?
STOCKHISTORY is included with a Microsoft 365 subscription that includes Excel and linked data types. There is no additional charge for the function itself, but you need a qualifying subscription. Free Excel online does not include STOCKHISTORY.
Can I use STOCKHISTORY for cryptocurrencies?
STOCKHISTORY is designed for stocks and other exchange-traded instruments. Cryptocurrencies are not supported by the function's data provider. You would need to use a different data source for crypto historical prices.
Why do I get a #NAME? error with STOCKHISTORY?
A #NAME? error typically means Excel does not recognize the function name. This happens if you are using a version of Excel that does not support STOCKHISTORY, or if the function name is misspelled. Check your Excel version and ensure you have a Microsoft 365 subscription.
How many rows can STOCKHISTORY return?
The number of rows depends on the date range and interval. Daily data for a year is about 252 rows (trading days). Excel's grid limit is 1,048,576 rows, but STOCKHISTORY may have its own limits based on the data provider. Very large requests may time out or return an error.
Does STOCKHISTORY include dividends and splits?
STOCKHISTORY returns raw price data and does not adjust for dividends or splits. The closing prices are as reported on each trading day. For adjusted data, you would need to use another source or perform adjustments manually.
Can I use STOCKHISTORY in Excel for Mac?
Yes, STOCKHISTORY is available in Excel for Microsoft 365 on Mac, provided you have a qualifying subscription and an internet connection. The function works the same as on Windows.