Skip to main content

Start using GPT functions in Sheets

GPT functions are custom spreadsheet functions in GPT for Sheets 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 spreadsheet to building formulas that combine GPT functions with native functions. The focus is on the GPT function, the simplest function included in GPT for Sheets, but the same rules apply to all GPT functions.

tip

To try out the examples in this guide, make a copy of our examples template.

Enable GPT functions

GPT for Sheets must be running before you can use GPT functions in a spreadsheet.

To start GPT for Sheets:

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

  2. In the menu bar, select Extensions > GPT for Sheets and Docs > Open.

    Launch GPT for Sheets

Use GPT functions

Learn the basics of using GPT functions, from how you write a function to what you need to keep in mind when using the 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:C3

value

No

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

  • Text: "Tone: Calm and serene"

  • Cell reference: A1

  • Range reference: A1:C3

The final prompt sent to the AI is prompt + value.

temperature

No

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

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 a dynamically calculated value — the result of the formula. The actual value of the cell is the formula expression: =GPT("Write a tagline for a tea house"). You cannot edit the calculated value; you can only edit the formula. If you want to set the calculated value 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 formula.

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 Sheets 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 for", B7)

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

    Write a tagline for antique store

    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. Sheets 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 for
  2. Select the first tagline cell and update the GPT function to reference the prompt cell. For example, if the prompt is in cell C6, enter:

    =GPT($C$6, B7)

    $C$6 is an absolute reference to C6, which you need here since you do not want Sheets to automatically adjust the reference when you fill the function 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$6, B7)
  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, overriding the existing formulas. Sheets automatically updates the business 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 complex 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 B9, with the tone in cell C9 and age range in cell D9, enter the following in cell E9:

    =GPT("Write a tagline for " & B9 & ", the tone is " & C9 & ", the audience is aged " & D9)

    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 B9 contains the text antique store, C9 contains nostalgic and refined, and D9 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 CONCATENATE function:

    =GPT(CONCATENATE("Write a tagline for ", B9, ", the tone is ", C9, ", the audience is aged ", D9))

    The GET function uses the CONCATENATE 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 included in GPT for Sheets:

    =GPT_CREATE_PROMPT("Write a tagline for", B9, ", the tone is", C9, ", the audience is aged", D9)
  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. Sheets automatically updates the cell references in the function so that each row receives a tailored response based on its business. The formula in row 10 will reference B10, C10, and D10; the formula in row 11 will reference B11, C11, and D11; and so on.

Combine GPT functions with native functions

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 statement. For example, if the business whose tagline you're generating is specified in cell B9 and the GPT function for that is GPT($C$6, B9), enter:

    =IF(B9="", "", GPT($C$6, B9))

    The GPT function runs only if cell B9 is not empty. If B9 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, overriding the existing formulas. Sheets automatically updates the business 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.

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.

If you provide the model parameter, and if the model is available both with and without an API key in GPT for Sheets, 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.

    =GPT("What was the previous month's inflation rate in the US?", , , "sonar")
  • 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")

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 Sheets 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 Sheets for parameter and decimal separators depend on your locale:

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

    =GPT("Write a tagline for", $A1)

    =GPT("Write a tagline for"; $A1)
  • Decimals: Some locales use the period (.) as the default decimal separator, while others use the comma (,). As a rule, locales that use the period for decimals use the comma for parameters, whereas locales 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 locale settings to verify which punctuation to use.

Formula auto-refresh

When your sheet auto-refreshes, Sheets 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 spreadsheet, Sheets reuses the formula's previously generated result from the cache.

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

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

Recalculation triggerWhat gets recalculated

Google Sheets automatically refreshes the spreadsheet every few hours

All formulas on the sheet

Open the spreadsheet (particularly if not accessed recently)

Potentially all formulas on the sheet

Insert, move, or delete a column

Formulas in subsequent columns

Insert, move, or delete a row

Formulas in subsequent rows

Sort rows

Formulas in rows that were moved

Move a formula to a different cell

Moved formula

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 need to process over a thousand cells at once. Sheets can reliably handle up to a few hundred simultaneous GPT function executions without noticeable slowdown — for example, when filling a formula down across 300 rows. Beyond this limit, performance starts to degrade; processing a few thousand cells at once can render the spreadsheet unresponsive. (Even if you delete loading formulas from the sheet, the formulas continue loading in the background; the performance impact persists, but you lose any results.)

  • Your formulas regularly time-out (especially with slow AI providers) or become stuck in the Loading state. If either happens during an auto-refresh, and if the cache has expired or is disabled, you risk losing your results.

  • 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 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.

What's next