With AI gradually making its way into every aspect of our lives, working in Excel has become much easier.
You no longer need to research the web and copy over the data into Excel. Simply prompt the AI in natural language, and it will spill out the results for you within Excel! All thanks to the Excel LABS.GENERATIVEAI function.
Using LABS.GENERATIVEAI you can even reference other cells or named formulas in your workbook.
We now have ChatGPT inside an Excel formula!

The image above illustrates the LABS.GENERATIVEAI function returning the airport codes for a list of airports in column J.
Note: LABS.GENERATIVEAI is available in Microsoft 365 & Office 2021 or later.
Table of Contents
- LABS.GENERATIVEAI Function Video
- Download Excel Example File
- LABS.GENERATIVEAI Function Overview
- Generating Lists from the Web
- Creating Content
- Analyzing Text
- Excel Formula Help
- How to Get LABS.GENERATIVEAI in Excel
- How to Optimize LABS.GENERATIVEAI Formula
- Tips and Best Practices
Watch the Video

Download Example File
Enter your email address below to download the sample workbook.
LABS.GENERATIVEAI Function Overview
The Excel LABS.GENERATIVEAI function is a custom function created by Excel Labs under Microsoft Garage. It allows you to send prompts directly from your Excel sheet to OpenAI’s generative AI model and quickly get the results you need.
The model analyses the information available to it, processes data, and produces a response based on the prompt you provide.
Overall, it works like a personal assistant that can speed up your spreadsheet creation process, reduce your research, and minimize the formula writing time. Now, you can just focus on the more important aspects of your analysis.
Let’s look at a few examples to understand what all LABS.GENERATIVEAI is capable of!
Generating Lists from the Web
The simplest application of LABS.GENERATIVEAI is to pull out standard information from the web, such as state abbreviations, airport codes, or international mobile phone codes.
For example, you need to create a state-wise demographics report of the US and need a list of all the 50 states with their abbreviations.
Instead of copying from the web, you can simply use the LABS.GENERATIVEAI function.
To list down all the 50 states, use the below formula:
=TRANSPOSE(TEXTSPLIT(LABS.GENERATIVEAI("return a comma separated list of the 50 states in the united states of america with no leading text"),", "))
By default, LABS.GENERATIVEAI renders the output in a single cell. Use TEXTSPLIT to split the comma-separated list and then TRANSPOSE it to return each state in a separate row.
Once you have that, simply reference this column to generate state abbreviations, using the below formula:
=LABS.GENERATIVEAI("return the state abbreviation for: "&B4)
Limitations
- Returns long outputs: At times, if you are not very specific with the LABS.GENERATIVEAI function, the output can be a full sentence instead of just what you need.
You can fix this by limiting the maximum output length or using the max_tokens argument of the function that we discuss later:
- Spilled array referencing constraint: The function can’t reference spilled arrays using the # operator, so you need to reference each individual cell within the array.
- Can be unreliable when asked to return tables: Even when specified in the prompt, at times, the output is a list instead of a table. So, it’s best to return the list and then use TEXTSPLIT and TRANSPOSE to return a table.
Creating Content
While extracting lists of data from the web is one application, LABS.GENERATIVEAI can also create new content for you.
Let’s say, you are starting an online gadgets store. You want to list 100 products in the store, and you need a short description for each of them.
You can go ahead and write them yourself, or simply use LABS.GENERATIVEAI to do it for you. In fact, you can even scrape the product specifications from the web using this function.
Let’s find out how.
Create a 3-column table in Excel as shown below:
Add your product list in the Product Name column.
In the Description column, use the below formula to generate short descriptions:
=LABS.GENERATIVEAI("Return a short description for this product: " &@[Product Name],0)
And in the Specs column, use the below formula to scrape specs from the web:
=LABS.GENERATIVEAI("Get the specs for the " &@[Product Name],0)
And within seconds you will have a snazzy-looking table with products, descriptions, and specs.
Limitations
- AI model can be outdated: AI models are updated periodically, so AI output can lag real-time information. For example, the Samsung Galaxy S23 has been released, but the AI still considers them unreleased because the model precedes the product release date.
- AI output is not error-free: As AI is still very new, some output might contain errors. It’s always a good practice to verify it after generation and clear out the errors.
Analyzing Text
LABS.GENRATIVEAI can even conduct sentiment analysis of your text. For example, here I have some comments from one of my videos on BYCOL and BYROW functions. Let’s analyze, and classify them into Positive, Negative and Neutral categories.
To do this, I will use the following formula:
=LABS.GENERATIVEAI("Use one word to summarise this text into positive, negative or neutral: "&[@Comment])
Within a few minutes, the function has completed the categorization. Now, I can get an idea of how people are reacting to my videos and create more videos to generate more positive comments.
Limitations
- Unreliable results: If a comment has both positive and negative comments, the model might not be able to analyze it perfectly, as seen in cell B9.
- Time-Consuming: The more data you want summarized, the more time the model takes to run.
However, even with all these limitations, LABS.GENERATIVEAI is a promising function for the future of Excel.
Excel Formula Help
Point LABS.GENERATIVEAI at a formula and have it explain how it works, step-by-step:
Use the FORMULATEXT function to expose the underlying formula in the cell and add it to the prompt:
=LABS.GENERATIVEAI("explain this formula step by step: "&FORMULATEXT(D6))
Limitations
- Not always correct: for example, point 1 above states that the table contains two columns, which isn’t true. The AI has assumed this because we only reference two columns in the formula, but the table actually contains 4 columns. While this isn’t going to cause any real issues, it’s a reminder that you can’t assume the AI is correct.
- Inconsistent results: sometimes the AI is more thorough than other times. You may need to recalculate the formula until you get an explanation that’s adequate.
How to get LABS.GENERATIVEAI in Excel
Go to Excel > Home Tab > Add-ins
Get Add-ins > Search for Excel Labs > Press Add
Once installed, you can access the Add-in from the Home Tab. It will open the sidebar on the right.
Scroll down to it > Press Open
Generate an OpenAI API Key > Enter the key in the box.
Once done, you can type in =LABS in any Excel cell, and you will see LABS.GENERATIVEAI function in the suggested formula list.
Also, make sure to optimize your settings.
How to Optimize LABS.GENERATIVEAI Formula
The syntax for the function is LABS.GENERATIVEAI(prompt, [temperature], [max_tokens], [model])
- Prompt is the only required argument in the function. It contains a description of what you want the generative AI model to return. It can be typed in double quotes or a reference to a cell containing the prompt, or a combination of both where the ampersand is used to concatenate the text and cell reference into a single prompt.
- Temperature is an optional argument used to control the model randomness. Lower temperature means less randomness; higher temperature means more randomness. If you want the model output to not update every time you refresh the formula, set the Temperature to 0. Note: this does not guarantee it will always return the same result.
- Max_tokens is also an optional argument that controls the output length. gpt-3.5-turbo offers 4097 tokens while gpt-4 offers 8192 tokens. One token is approximately 4 English characters. You can use the OpenAI Tokens guide to find out how many tokens you need to specify in your formula.
- Model is also an optional argument. It allows you to pick the model you want to run with your LABS.GENERATIVEAI command. gpt-4 is the latest release and is much more reliable compared to its predecessors.
You can pass specific values for these parameters in your function to get more accurate results.
Tips and Best Practices
To get the desired results, you must follow the below best practices:
- Be precise: The more accurate your prompt is the better results the function will render.
- Keep your prompts simple: LABS.GENERATIVEAI returns better results when supplemented with other EXCEL functions, like we explained using TEXTSPLIT and TRANSPOSE instead of asking it to return a table.
- Volatile: The LABS.GENERATIVEAI formulas appear to be volatile, recalculating every time any other formulas on the sheet are edited or structural changes like inserting or deleting rows and columns are made. To avoid this, paste the output as values, or while writing the formulas put the workbook into Manual calculation mode:
WARNING: Don’t forget to recalculate the workbook using the F9 key or by putting the workbook back into Automatic Calculation mode.
- Fund your account: #N/A, #BUSY! errors can mean that you need to add funds to your OpenAI account at https://platform.openai.com/account/billing/overview When co-authoring, all accounts should be funded otherwise the formula breaks.
- Daily token limits: watch out for the daily limits on tokens as these can be easily reached and will also result in errors like #BUSY! that eventually returns #N/A!. Limits vary based on your plan. You can see them when logged into your OpenAI account in the Settings > Limits section.
Tip: if you reach your daily limit, try changing the model you’re using in the Excel Labs settings for LABS.GENERATIVEAI.
AI Is Everywhere
There are many ways you can leverage AI both inside and outside Excel. Check out these examples next:
Automate Excel with ChatGPT

8 AI Game Changers - Official Microsoft Tools to Skyrocket Productivity

Excel Writes Formulas by Example

Excel AI Formula Writer: Advanced Formula Environment

Hi Mynda,
I have been constantly following you for the immensly knowledgable content and videos that you keep uploading time to time… thanks for the same. Towards the video that you shared for the “LABS.GENERATIVEAI” function … I tried using the same with all the details that you shared however I always get “#NA” as a result and as an explanation to the same it says “You exceeded your current quota. Please check your plan and billing details. For more information on this error please visit https://platform.openai.com/docs/guides/error-codes/api-errors” and the error code refers – “429 – You exceeded your current quota, please check your plan and billing details”…… I checked my account within the OpenAI site and have sufficient balance in the same as the utilization is ZERO as of now and the limit is set at USD80.00 ……. I am unable to understand why this error is appearing …. Please share your support in helping me resolve this error.
Hi Mukesh,
There can be a few reasons for that error:
Account Activation Delay: If you’ve recently added credits to your account, it might take some time for the payment to process and for your account to become fully active. During this period, even with a positive balance, you might encounter quota errors. Users have reported similar experiences where, despite having sufficient balance, they received quota errors due to processing delays.
https://community.openai.com/t/i-just-signed-up-and-paid-but-i-got-error-429-my-limit-is-still-untouched/1085018?utm_source=chatgpt.com
Usage Limits and Tiers: OpenAI assigns usage tiers based on your payment history. If your account is new or has limited payment history, it might be placed in a lower usage tier with stricter limits. To check and adjust your usage limits, navigate to the Limits section of your account settings. If you find that your current limits are insufficient, you can request an increase by following the guidelines provided:
https://help.openai.com/en/articles/6891831-error-code-429-you-exceeded-your-current-quota-please-check-your-plan-and-billing-details?utm_source=chatgpt.com
Hi Catalin,
Thank you for sharing your prompt response.
I tried the options that you mentioned in your message however some how I am still getting the same error message “429 – You exceeded your current quota, please check your plan and billing details” —- I checked once again at my existing balance and the same reflects the utilization is ZERO and the amount is still appearing as pending… not sure where am I going wrong … request you to please help me
Regards
Mukesh Chopra
1. Verify Your API Key & Organization
Confirm your API key is still valid and active.
Go to OpenAI’s API Keys page to check if your key is live.
If you have multiple keys, ensure you’re using the correct (and most recent) one.
Check if you’re using the correct organization.
Some users have more than one organization (e.g., a personal one and a business one).
In the API keys section of your dashboard, make sure the Organization ID associated with your chosen key matches what the Labs.GenerativeAI function or your Excel setup expects (if it does require specifying Org ID).
Regenerate or create a new secret key and test again. Sometimes older keys can malfunction if you have changed billing details or organizational settings.
2. Confirm Billing & Usage Settings
Check “Hard Limits” for Your Organization:
Log into your OpenAI Usage Dashboard.
You’ll see two relevant monthly usage limits: a “Soft limit” and a “Hard limit.”
If your “Hard limit” is set to something lower than $80, the system might interpret you have no budget left. Or, if your soft limit is set to $0, usage could be blocked.
Add a Payment Method or Ensure Payment Method Is Current:
Even if you have $80 in usage limit, OpenAI still requires a valid payment method on file for the paid account.
Make sure your credit card or payment method is up to date.
If you only have free credits and your free trial period has expired, you will need to add a billing method to continue using the API.
Confirm You Are Not Hitting Rate Limits
Even if you have money left, if your requests per minute are higher than allowed or you have a short-term usage spike, you could trigger a temporary rate-limit error.
Check your usage graphs under “Usage” to see if there is a spike.
3. Double-Check the Setup in Excel (Labs.GenerativeAI Function)
Ensure your API key is correctly referenced in your Excel function or in the add-in settings.
Typically, the function might look like:
,
excel
Copy
Edit
=LABS.GENERATIVEAI(
“text-davinci-003”,
“Write a short poem about autumn”,
…
)
If your function references an environment variable (like _OPENAI_API_KEY), verify that environment variable is set correctly in your system or Excel settings.
Check for Typos in the Key.
A single character typo in your secret key will cause authentication to fail or show erroneous quota messages.
Update / Reinstall the Add-In (if relevant)
If you’re using a custom add-in or a script in Office Scripts that calls the API, an outdated version might cause issues.
Try removing and adding it back, then re-inserting the correct API key.
4. Try Simple API Tests Outside of Excel
To isolate whether the problem is your Excel function or your OpenAI account:
Use cURL or Postman (or any REST tool) to make a simple API call:
bash
Copy
Edit
curl https://api.openai.com/v1/models \
-H “Content-Type: application/json” \
-H “Authorization: Bearer YOUR_API_KEY”
If you get a response listing the models, your key and account are okay.
If it returns a 429 or quota error, the issue is definitely on the OpenAI side (quota or billing setup).
If cURL/Postman works but Excel fails with a 429, that almost always indicates an issue with how the API key or environment variable is passed in the Excel function.
5. Contact OpenAI Support If Issue Persists
If you have:
Verified your API key
Confirmed correct billing details and usage limits
Ensured you are using the correct org and not hitting rate limits
Successfully tested your key in a different context (like Postman or cURL)
…and you still get the 429 error in Excel, reach out to OpenAI Support (using the help widget or contact form at https://help.openai.com/). Provide them:
Your Organization ID
The last few digits of your API Key (never share the entire key)
Screenshots of your usage page and your Excel setup
They can check logs on their end to see why the requests are being denied.
Hi Mynda For the new API key to work ensure that the API box is cleared of all symbols before the new key is entered
Thanks for your worksheet sample
David Ormandy
Thanks for sharing the tip, David.