Skip to main content

Start using GPT functions in Excel

GPT functions are custom spreadsheet functions in GPT for Excel that allow you to prompt AI from inside spreadsheet cells. GPT functions work exactly like native functions in that you can use them on their own or combine them with other functions when creating formulas.

This guide walks you through the basics of using GPT functions — from enabling GPT functions for a workbook through building formulas with GPT functions to using functions for web search and image processing. The focus is on the GPT function, the simplest function included in GPT for Excel, but the same rules apply to all GPT functions.

tip

To try out the examples in this guide, download our GPT function starter examples template, and open it in Excel as a new workbook.

Enable GPT functions

GPT for Excel must be running before you can use GPT functions for the first time in a workbook.

To start GPT for Excel:

  1. Open the workbook where you want to use GPT functions.

  2. In the Home tab, click GPT for Excel Word.

    GPT for Excel Word in the Home ribbon

    info

    You can also select Home > Add-ins > My Add-ins > GPT for Excel Word.

Use GPT functions

Learn the basics of using GPT functions, from how you type a function through how you use functions in formulas to how you search the web and process images with functions.

GPT function syntax

Each GPT function follows a specific syntax that consists of a function name and one or more parameters (also called "arguments") enclosed in parentheses. The parameters together tell the function what to do. Some parameters are required, while others are optional. The syntax of a function is presented as follows:

FUNCTION_NAME(parameter_1, parameter_2, [parameter_3])

The order of the parameters matters, so always write them in the order required by the function syntax. Optional parameters are in square brackets.

For example, the GPT function has the following syntax:

GPT(prompt, [value], [temperature], [model])

The GPT function takes the following four parameters:

ParameterRequiredDescription

prompt

Yes

The prompt for the AI. The prompt can be:

  • Text: "Write a tagline for a tea house"

  • Cell reference: A1

  • Range reference: A1:A3

value

No

Input that you want to combine with the prompt. The input can be:

  • Text: "Tone: Calm and serene"

  • Cell reference: B1

  • Range reference: B1:B3

If you provide value, GPT for Excel uses the following template to build the final prompt sent to the AI:

<prompt>
Input: <value>
Output:

For example, if prompt is Write a tagline for a tea house and value is Tone: Calm and serene, the final prompt is:

Write a tagline for a tea house
Input: Tone: Calm and serene
Output:
info

The Output line serves as a structural anchor that helps constrain the model into returning a clean, direct, and well-formatted response.

If you do not provide value, GPT for Excel sends prompt as is.

temperature

No

Number between 0 and 1 that specifies how creative the AI should be in generating the response:

  • 0 sets minimum creativity. Responses to the same prompt are predictable and very similar.

  • 1 sets maximum creativity. Responses to the same prompt can vary wildly. Highest risk of hallucination.

model

No

Name of the AI model that you want to use. You can find the model names in the model switcher in the add-in sidebar. Learn more.

The first parameter of the GPT function is required, so you always have to provide it. The remaining three parameters are optional, so you only need to provide them when you want additional control over how the function operates. You can provide one, two, or all three optional parameters, depending on your needs.

Double quotes

If a parameter takes a text value, always enclose the text in double quotation marks. For example:

GPT("Write a tagline for a tea house")

GPT(Write a tagline for a tea house)

The latter fails with an error because the function cannot interpret the words as valid parameters.

Empty parameters

If you skip an optional parameter other than the last one, always provide a lone comma ("empty parameter") as a placeholder to maintain the correct syntax. For example:

GPT("Write a tagline for a tea house", , 0.5, "claude-4-sonnet")

GPT("Write a tagline for a tea house", 0.5, "claude-4-sonnet")

The latter fails with an error because the function treats 0.5 as the second parameter (value, which expects text or a reference) and "claude-4-sonnet" as the third parameter (temperature, which expects a number).

Run a GPT function

To use the GPT function:

  1. Select a cell where you want the response to appear.

  2. Type the equal sign = followed by the function. For example, to use the GPT function with just the prompt parameter, type:

    =GPT("Write a tagline for a tea house")
  3. Press ENTER.

The function runs: It sends the prompt to the AI, receives a response, and displays the response in the selected cell.

Calculated values and constants

The text you see in the cell is the result of the formula — a dynamically calculated value. The actual value of the cell is the formula expression: =GPT("Write a tagline for a tea house"). You cannot edit the result; you can only edit the formula. If you want to set the result as the actual value of the cell, that is, if you want to turn the calculated value into a constant that you can edit, replace the formula with its result.

Calculated value and actual value of a GPT formula cell

Reference other cells from a GPT function

You can reference other cells and ranges from a GPT function. You can use relative, absolute, and mixed references as you would with any function.

For example, to retrieve the prompt for the GPT function from another cell:

  1. Select a cell and enter the prompt:

    Write a tagline for a tea house
    tip

    You do not need double quotation marks around the prompt here because Excel automatically returns the value as text.

  2. Select another cell and enter the GPT function with the prompt cell as the only parameter. For example, if the prompt is in cell B12, enter:

    =GPT(B12)

    The function runs and returns the AI's response in the selected cell.

Both GPT(B12) and GPT("Write a tagline for a tea house") work the same way — they send the exact same prompt to the AI. The only difference is that the former retrieves the prompt from a cell, while the latter provides it directly as a text constant in the function.

Apply the same prompt to multiple cells

You can apply the same GPT function and prompt to adjacent cells by filling the formula across a range.

For example, suppose you want to generate unique taglines for multiple businesses. The businesses are listed in one column of your sheet, and you want to fill another column with the corresponding taglines. You can generate the taglines by using the GPT function with the prompt and value parameters, where prompt specifies the basic instructions and value specifies a specific business as a cell reference:

  1. Select the first tagline cell and enter the GPT function. For example, if the business whose tagline you're generating is specified in cell B7, enter:

    =GPT("Write a tagline", B7)

    The function combines the two parameters into a single prompt, based on the underlying prompt template, which is then sent to the AI. For example, if B7 contains the text antique store, the final prompt sent to the AI is:

    Write a tagline
    Input: antique store
    Output:

    The function runs and returns the AI's response in the selected cell.

  2. Fill the formula down to apply it to the rest of the column: Select the fill handle and drag it down across the cells you want to fill. Excel automatically updates the cell reference in the function so that each row receives a tailored response based on its business. The formula in row 8 will reference B8, the formula in row 9 will reference B9, and so on.

To see how absolute references work, let's move the prompt to its own cell:

  1. Select an empty cell and enter the prompt:

    Write a tagline
  2. Select the first tagline cell and update the GPT function to reference the prompt cell. For example, if the prompt is in cell C8 and the business whose tagline you're generating is now specified in cell B11, enter:

    =GPT($C$8, B11)

    $C$8 is an absolute reference to C8, which you need here since you do not want Excel to automatically adjust the reference when you fill the formula to adjacent cells.

    tip

    Since you're only filling vertically across a single column, it would be enough to fix the prompt cell row using a mixed reference:

    =GPT(C$8, B11)
  3. Fill the formula down to apply it to the rest of the column: Select the fill handle and drag it down across the cells you want to fill, overwriting the existing formulas. Excel automatically updates the value cell reference for each row, while keeping the prompt cell reference fixed.

Create a prompt by combining text from multiple cells

You can use concatenation to combine text from two or more cells into a single text string. This allows you to create advanced prompts, where different parts of the prompt come from different cells in the sheet.

For example, suppose you want to further customize the taglines of the previous example, so that they follow a specific tone and target a specific customer age range. The businesses are listed in the first column, the tone in the second, and the age range in the third, with the fourth column now reserved for the taglines.

To build the prompt by combining the information from the different columns:

  1. Select the first tagline cell and enter the GPT function. For example, if the business whose tagline you're generating is specified in cell B11, with the tone in cell C11 and age range in cell D11, enter the following in cell E11:

    =GPT("Write a tagline for " & B11 & ", the tone is " & C11 & ", the audience is aged " & D11)

    The function uses the & operator to concatenate the different parts, which include literal text values and cell references, into a single text string. For example, if B11 contains the text antique store, C11 contains nostalgic and refined, and D11 contains 35-65, the final prompt sent to the AI is:

    Write a tagline for antique store, the tone is nostalgic and refined, the audience is aged 35-65
    tip

    Instead of the & operator, you can also use the native CONCAT function:

    =GPT(CONCAT("Write a tagline for ", B11, ", the tone is ", C11, ", the audience is aged ", D11))

    The GPT function uses the CONCAT function as a nested function. Learn more.

    If you want to concatenate without having to worry about white spaces and newlines, use the GPT_CREATE_PROMPT function:

    =GPT(GPT_CREATE_PROMPT("Write a tagline for", B11, ", the tone is", C11, ", the audience is aged", D11))
  2. Fill the formula down to apply it to the rest of the column: Select the fill handle and drag it down across the cells you want to fill. Excel automatically updates the cell references in the function so that each row receives a tailored response based on its business. The formula in row 12 will reference B12, C12, and D12; the formula in row 13 will reference B13, C13, and D13; and so on.

Combine a GPT function with a native function

You can combine GPT functions with native functions like you would any other function.

For example, suppose you want to run the GPT function from above only when the current row has a business specified. If the business cell is empty, you want to skip the row. You can do this by combining the GPT function with the native IF function:

  1. Select the first tagline cell and enter a formula that wraps GPT inside an IF function. For example, if the business whose tagline you're generating is specified in cell B11 and the GPT function for that is GPT($C$8, B11), enter:

    =IF(B11="", "", GPT($C$8, B11))

    The GPT function runs only if cell B11 is not empty. If B11 is empty, the formula leaves the current cell empty, too.

  2. Fill the formula down to apply it to the rest of the column: Select the fill handle and drag it down across the cells you want to fill, overwriting the existing formulas. Excel automatically updates the value cell reference for each row, while keeping the prompt cell reference fixed.

  3. To see the conditional logic in action, empty one of the business cells. The formula for that row reruns and removes the tagline.

Search the web with a GPT function

You can search the web with a GPT function simply by using a web search model. You can either select the model in the model switcher or specify the model with the model parameter.

For example, suppose you want to do a search for company CEOs. The companies are listed in one column of your sheet, and you want to fill the next column with the CEO names.

  1. In the sidebar, expand the model switcher and select a web search model (indicated by the 🌐 icon).

    Select model
    info

    If you select a Gemini model, make sure web search is enabled for Gemini models.

  2. Select the first CEO cell and enter the GPT function. For example, if the company whose CEO you're fetching is specified in cell B13, enter:

    =GPT("Give me this company's current CEO. I only want the name of the CEO, no citations.", B13)
    tip

    If you want to override the model switcher selection, specify the model in the GPT function with the model parameter. For example, if you want to use the Sonar model, enter:

    =GPT("Give me this company's current CEO. I only want the name of the CEO, no citations.", B13, , "sonar")
  3. Fill the formula down to apply it to the rest of the column: Select the fill handle and drag it down across the cells you want to fill. Excel automatically updates the company cell reference for each row.

For more information about web search, see Search the web with GPT for Excel.

Process images with GPT_VISION

You can apply a text prompt to an image using the GPT_VISION function with a vision model. You can either select the model in the model switcher or specify the model with the model parameter.

For example, suppose you want to extract the brand name from product images featuring coffee bean packs. The image URLs are listed in one column of your sheet, and you want to fill the next column with the brand names.

  1. In the sidebar, expand the model switcher and select a vision model.

    To determine whether a model supports vision, check its info popup. For a list of available vision models, see AI providers & models and filter the tables by Vision.

    Select model
  2. Select the first image URL cell and enter the GPT function. For example, if the image URL that you want to process is in cell C13, enter:

    =GPT_VISION("Extract the coffee brand from this image. Normalize the brand name to title case.", C13)
    tip

    If you want to override the model switcher selection, specify the model in the GPT function with the model parameter. For example, if you want to use the Claude Sonnet 4 model, enter:

    =GPT_VISION("Extract the coffee brand from this image. Normalize the brand name to title case.", C13, , , "claude-4-sonnet")
  3. Fill the formula down to apply it to the rest of the column: Select the fill handle and drag it down across the cells you want to fill. Excel automatically updates the image URL cell reference for each row.

For more information about AI vision, see Use images in prompts in Excel.

Set the model for a GPT function

You can run a GPT function with a specific model by providing the model parameter. The function will ignore what's currently selected in the model switcher and use the provided model instead.

For example, if you want the Perplexity Sonar model to answer a query about current events, provide sonar as the model:

=GPT("What was the previous month's inflation rate in the US?", , , "sonar")
info

If the model is available both with and without an API key in GPT for Excel, the function uses the model with the API key.

Use the model parameter when:

  • You want to lock a formula to a specific model. For example, if you have a web search formula, you want it to consistently use the same web search model.

  • You want to compare how a specific model compares with other models. For example, use the same GPT function and prompt in two formulas — the first with the model parameter, the second without — and then use the model switcher to change the model used by the second formula, regenerating its response after each change.

    =GPT("Write a tagline for a tea house", , , "claude-4-sonnet")

    =GPT("Write a tagline for a tea house")

Set the creativity level for a GPT function

You can run a GPT function with a specific creativity level by providing the temperature parameter. The function will ignore the creativity level defined in the model settings and use the provided level instead.

For example, if you're working on a creative task and want to experiment with highly creative responses, set the temperature close to 1:

=GPT("Write a three-sentence horror story about a teahouse.", , 0.9);

For more information about temperature, see our temperature guide for OpenAI models.

GPT functions: Defaults, settings, behavior

Default model

By default, GPT functions use the currently selected model. If you want a GPT function to use a specific model regardless of what's currently selected in the model switcher, use the model parameter to explicitly set the model.

info

If you provide the model parameter, and if the model is available both with and without an API key in GPT for Excel, the function uses the model with the API key.

Default creativity level

By default, GPT functions use the creativity level defined in the model settings. If you want a GPT function to use a specific creativity level regardless of what's defined the model settings, use the temperature parameter to explicitly set the creativity level.

Global instructions and advanced settings

The global instructions and advanced settings defined in the GPT for Excel sidebar apply to GPT functions. If you find that a function is not working as expected, check the model settings for a possible cause.

Regional settings

The default characters used by Excel for parameter and decimal separators depend on your currently selected region:

  • Parameters: Some regions use the comma (,) as the default parameter separator, while others use the semicolon (;).

    =GPT("Write a tagline", B7)

    =GPT("Write a tagline"; B7)
  • Decimals: Some regions use the period (.) as the default decimal separator, while others use the comma (,). As a rule, regions that use the period for decimals use the comma for parameters, whereas regions that use the comma for decimals use the semicolon for parameters.

    =GPT("Write a tagline for a tea house", , 0.5)

    =GPT("Write a tagline for a tea house"; ; 0,5)

The examples in the current documentation use the comma as the parameter separator and the period as the decimal separator. If the examples fail with syntax errors in your workbook, check your regional settings to verify which punctuation to use.

Formula auto-refresh

When your sheet auto-refreshes, Excel automatically recalculates some or all formulas on the sheet, including GPT formulas. For each GPT formula:

  • If the GPT formula cache is enabled for the workbook, Excel reuses the formula's previously generated result from the cache.

  • If the cached result has expired, or if you have the cache disabled, Excel runs the formula normally.

In Excel, the following triggers cause a sheet to auto-refresh:

Recalculation triggerWhat gets recalculated

Insert, move, or delete a column

All formulas on the sheet

Insert, move, or delete a row

All formulas on the sheet

Filter rows by column

All formulas on the sheet

Hide and unhide rows

Formulas in the selected rows

Sort rows

Formulas in the selected rows

Move a formula to a different cell

All formulas on the sheet

Undo the deletion of a formula from a cell

Restored formula

To prevent GPT formulas from being recalculated, replace the formulas with their results.

When to use bulk AI tools

Consider using bulk AI tools instead of GPT functions if:

  • You want AI responses saved as plain text in cells. Bulk AI tools fill cells with static text values, or constants, so you don't need to replace any formulas. You also avoid formula auto-refresh, reducing the risk of unintended data changes.

  • You want better tracking information about the progress of AI requests. Bulk AI tools provide a live progress tracker that shows you how many rows have been successfully processed, how many have resulted in an error, and how much time has elapsed.

  • Your formulas regularly become stuck in the #BUSY! state.

What's next