Create Custom Excel Formulas That Update Automatically
To make an Excel formula that updates by itself, write it as a small Python function in the free xlwings Lite add-in. Make the function async, fetch the data in a loop, and use yield instead of return. Excel then refreshes the cell every time the function yields, for example a live crypto price every second, while you keep working.
Table of contents
How it works
Excel has no built-in formula that calls any web API and refreshes on its own. A custom function written in Python can do both. It fetches the value, hands it to the cell, waits a moment and fetches again, so the cell keeps changing as long as the workbook is open.
The value can live anywhere that answers a web request: a crypto exchange, an exchange rate service, or the API of your own warehouse or order system. I use live crypto prices because you can watch them change, then show an exchange rate dashboard, which is the more practical business case.
All of it runs in xlwings Lite, a free add-in from the Office Add-in Store that puts a Python editor in Excel’s task pane. You do not install Python. The code runs locally on your computer and is saved inside the workbook. Only the web requests your function makes leave your machine.

Ways to get live data into Excel
There are four common ways: Excel’s Stocks and Currencies data types, Power Query, an RTD add-in, and a streaming Python function. Only the last one is a plain formula you type into any cell, point at any API and leave running without a refresh button.
| Option | How it refreshes | Data source | Works as a cell formula |
|---|---|---|---|
| Stocks and Currencies data types | Refresh All, or a refresh setting | Only what Microsoft’s data provider offers | Through the data type fields |
| Power Query | Refresh All, or a scheduled refresh | Most APIs and files | No, it loads a table |
| RTD server (COM add-in) | Pushes updates | Whatever the developer builds | Yes, Windows only, needs a developer |
| Python function in xlwings Lite | On every yield, for example every second |
Any API that answers browser requests | Yes, also inside tables |
If you only need yesterday’s exchange rate in a report, Power Query or the Currencies data type is enough. The Python route is worth it when you want a formula you can drag down a table, feed with a cell reference, and point at your own data source.
Setup
You need Excel for Microsoft 365 or Excel 2021 or newer, the free xlwings Lite add-in, an internet connection, and one extra Python package called httpx. The add-in works in Excel on Windows, on a Mac and in Excel on the web.
-
Install xlwings Lite. In Excel go to Home, then Add-ins, then More Add-ins. Search for xlwings Lite, click Add and then Continue. The xlwings Lite pane opens on the right. If you have never used it, my introduction to xlwings Lite walks through the pane.
-
Add httpx to the requirements. Open the requirements.txt tab in the pane and type
httpxon a new line. httpx is the package that fetches data from the web. -
Restart the add-in. xlwings Lite shows a “Dependencies changed” message. Click Restart so the package loads. Skip this and Python cannot import httpx.

A function that calls an API
Write a normal Python function, put @func above it, and save. xlwings Lite registers it as an Excel function with the same name in capitals. Inside, httpx requests the price from the API and the function returns the number to the cell.
For the example I use Binance’s public price endpoint. It needs no API key and answers with a small piece of JSON per trading pair, such as {"symbol":"BTCUSDT","price":"..."}. USDT is a coin that tracks the US dollar, so the BTCUSDT price works as a dollar price. Paste this into main.py:
import httpx
from xlwings import func
BINANCE_URL = "https://api.binance.com/api/v3/ticker/price"
# Async lets Excel keep working while we wait for the price to come back.
@func
async def crypto_price(coin):
"""Return the coin price in USDT."""
async with httpx.AsyncClient() as client:
pair = f"{coin.upper()}USDT"
response = await client.get(BINANCE_URL, params={"symbol": pair})
return float(response.json()["price"])
What each part does:
@functurns the Python function into the Excel functionCRYPTO_PRICE. The docstring shows up as help text in Excel’s function wizard.coinis the argument you pass from Excel, such as “BTC” or a cell reference.asyncandawaitlet Excel stay responsive while the request is on its way. Custom functions in xlwings Lite always run in the background, and the cell shows#BUSY!until the answer arrives.float(...)is needed because the API sends the price as text.
Now type the formula. In a table with a Coin column, enter =CRYPTO_PRICE([@Coin]) in the first Price cell and Excel fills the whole column. A Value column with =[@Amount]*[@[Price (USD)]] and a total below turn it into a small portfolio.
This version is static. It fetches the price once, when you enter the formula or when Excel recalculates it. To get a fresh price you would have to re-enter the formula.
Refresh every second
Wrap the request in a while True loop, replace return with yield, and wait one second at the end of each round with asyncio.sleep. A function that yields is a streaming function: it keeps running and sends a new value to the cell on every pass.
import asyncio
import httpx
from xlwings import func
BINANCE_URL = "https://api.binance.com/api/v3/ticker/price"
# Async lets Excel keep working while we wait for the price to come back.
@func
async def crypto_price(coin):
"""Return the coin price in USDT."""
async with httpx.AsyncClient() as client:
while True:
pair = f"{coin.upper()}USDT"
response = await client.get(BINANCE_URL, params={"symbol": pair})
yield float(response.json()["price"])
await asyncio.sleep(1)
asyncio is part of Python, so it does not go into requirements.txt. Save the file and every price in the table starts to tick, and the total moves with it. Excel stays usable the whole time: you can add sheets, type other formulas and format cells while the prices update in the background.
Compare the two versions: the loop, yield, the sleep and the asyncio import are the only changes. That is the whole trick.
Tip: one second is right for a demo. For business data that changes a few times a day, use asyncio.sleep(60) or more. Every cell with the formula sends its own request on every round, so a 100-row table at one second means 100 requests per second.
Live dashboards
Yes. Once a function streams values, Excel does the rest with ordinary tools: tables, number formats and conditional formatting. A function can also yield a whole list of rows, which spills into the grid like any dynamic array and refreshes as one block.
The crypto dashboard uses four streaming functions:
=TICKER_PRICE("BTCUSDT")streams one price every second.=TICKER_CHANGE("BTCUSDT")streams the 24-hour change as a percentage.=CRYPTO_BOARD()sits in one cell and spills a market table for eight coins: price, 24-hour change, high, low and volume.=TOP_MOVERS(8)scans every USDT pair on the exchange and lists the biggest 24-hour gainers.

Green and red come from regular conditional formatting on the change cells, not from Python.
The exchange rate dashboard is the one I would actually use at work. It reads the European Central Bank reference rates from the free Frankfurter API, which needs no API key. The base currency sits in one input cell. Type USD instead of EUR, press Enter, and the rate cards and the table of major rates with 1-day and 1-week changes follow. A cross-rate grid and a currency converter sit next to them. The ECB publishes once per business day, so these functions check every 60 seconds instead of every second.

If you would rather chart the numbers than tick them, the same add-in can turn a table into an HTML chart. I show that in my post on interactive Excel charts with pyecharts.
Downloads
All three workbooks are below. The Python code is already stored inside each file, so you open it, install xlwings Lite if you have not yet, and the functions register by themselves. Each file has a short how-to section.
Live crypto price formula (starter workbook)
The portfolio table from the video with an empty Price column, ready for =CRYPTO_PRICE([@Coin]), plus a Start Here sheet with the steps.
Live crypto dashboard
Price cards, a spilling market table and the top gainers, driven by four streaming functions.
Live exchange rate dashboard
ECB reference rates with a base-currency input cell, 1-day and 1-week changes, a cross-rate grid and a converter.
Use your own API
Keep the structure and change three things: the URL, the parameters you send, and the field you read from the JSON answer. If your API needs a key, send it as a header. The loop, the yield and the sleep stay exactly as they are.
Good candidates are anything that changes during the day and already has an API: stock levels from a warehouse system, the status of an order, the queue length in a support tool, or a metric from an internal dashboard. Start with the one-shot version that uses return. Once it shows the right number, switch it to streaming.
xlwings Lite also has a built-in AI assistant called Wingman. Connect it to a model such as ChatGPT or Claude, paste the crypto function and describe your API, and it rewrites the code for you. I show how to set up Wingman in my post on building an Excel dashboard with Python and AI. Read the code it gives you before you point it at a company system.
If your data sits in a database rather than behind an API, a query function can work too. My post on running SQL queries as an Excel formula shows that pattern. For custom formulas that do not need live data at all, such as text extraction or grouping a table, see my guide to custom Excel formulas with Python.
Troubleshooting
#BUSY! means the function is still waiting for its first answer. #VALUE! means Python raised an error, and hovering over the cell shows the message. Most problems come from a missing package, a typo in the symbol, or an API that refuses the request.
| What you see | Likely cause | Fix |
|---|---|---|
#BUSY! for a long time |
The add-in is still loading packages, or the request hangs | Wait for the first load, check your internet connection, and look at the Output panel in the pane |
#VALUE!, message mentions httpx |
httpx is not in requirements.txt, or the add-in was not restarted | Add httpx and click Restart |
#VALUE! for one coin only |
The symbol does not exist on the exchange. Binance answers “Invalid symbol” and there is no price field to read | Check the spelling, or that the coin trades against USDT |
#VALUE! in the United States |
api.binance.com refuses requests from the US with HTTP 451 | Change the URL to https://api.binance.us/api/v3/ticker/price, the US mirror with the same endpoint |
| “Failed to fetch” in the Output panel | xlwings Lite runs Python in the browser engine, and the API does not allow browser requests (CORS) | Use an API or endpoint that allows browser requests. The FX dashboard uses api.frankfurter.dev for that reason |
| Prices stop changing | The workbook was closed, or the add-in pane was reloaded | Streaming runs only while the workbook is open with the add-in loaded. Reopen it and the formulas start again |
Watch out: this is a learning example, not a trading tool. Public price endpoints can lag, rate-limit you or change. Do not base money decisions on a cell that refreshes from a free API.
Normal formulas that do not update
When regular formulas such as SUM or VLOOKUP stop updating, the workbook is almost always set to manual calculation. Go to Formulas, then Calculation Options, and pick Automatic. Pressing F9 recalculates once without changing the setting.
Manual calculation often sneaks in from another workbook. Excel applies the calculation mode of the first workbook you open in a session, so a file saved in manual mode can switch everything else to manual too. Formulas shown as text, with the formula itself visible in the cell, are a different problem: the cell is formatted as Text, or Show Formulas is turned on under the Formulas tab.
Live data is a separate question. A normal formula only recalculates when its inputs change. Even volatile functions like NOW only update when something triggers a recalculation. That is the gap the streaming Python function fills.
Sharing the workbook
Yes. The Python code lives inside the .xlsx file, next to your data and formulas. A colleague who opens it only needs the free xlwings Lite add-in from the Office Add-in Store. They do not need Python, a macro-enabled file, or a security prompt for VBA.
Two things still apply on their side. The API has to be reachable from their network, and if the API needs a key, they need their own. Everything else travels with the file, which makes this a simple way to hand a small live tool to a team.
