What is setValue in Google Sheets Apps Script?

setValue writes a single value into one cell on a Range object. Pass a string, number, boolean, or Date and Apps Script stores it in the grid. It is the simplest write operation and appears constantly in triggers, menus, and small automations that update one field at a time.

When to use it

Use setValue for single-cell updates: stamp a timestamp, flip a status flag, write a computed ID into one cell, or clear one field with an empty string.

When to skip it

Skip setValue when updating many cells. Build a 2D array and use setValues once. Repeated setValue calls in large loops are slow and can hit execution limits.

How it works

  1. 1

    Get a Range with getRange('E5') or offset from a known row.

  2. 2

    Call range.setValue(value) with the data you want stored.

  3. 3

    JavaScript Date objects usually become proper date values in the cell.

  4. 4

    Use setNumberFormat after setValue if display format matters for your team.

  5. 5

    In onEdit, avoid writing back to e.range without checking oldValue to prevent loops.

  6. 6

    Test on a copy because script writes do not Undo with Ctrl+Z.

Examples in Google Sheets

Last updated stamp

onEdit sets the cell in column F on the same row to new Date() when column D changes to Done.

Reset a control cell

After processing, setValue on Settings!A1 back to READY so the next menu run knows the job finished.

Write an error message

catch block calls getRange('B1').setValue('API failed at ' + new Date()) for a visible status on the Dashboard tab.

Build this without starting from a blank cell

Use a Better Sheets tool for setValue, then watch a walkthrough when you want the full pattern.

Better Sheets resources

Common mistakes

  • setValue inside a loop over thousands of rows instead of batching with setValues.
  • Writing to the trigger cell in onEdit without guards, causing infinite re-fires.
  • Passing a string when the sheet expects a number, breaking downstream SUM formulas.
  • Overwriting formula cells with setValue and deleting logic users relied on.
  • Using setValue on merged cells in ways that confuse which master cell receives the value.

Frequently asked questions

What is the difference between setValue and setValues?
setValue writes one cell. setValues writes a 2D array to a matching rectangular range in one call.
Can setValue write a formula?
Yes. Pass a string starting with = and Sheets stores it as a formula. setFormula is clearer when you only set formulas.
How do I clear a cell?
Call setValue('') or clearContent on the range. clearContent also removes formatting.
Does setValue trigger onEdit?
Yes, when a user-visible edit path runs. Script writes from the same onEdit handler can re-fire the trigger if you are not careful.
Can setValue set a checkbox?
Pass true or false boolean for checkbox cells formatted as checkboxes.
Why is my date wrong?
Timezone and Date object time can shift display. Set timezone in script settings or write a date-only value intentionally.
Can setValue run in simple onOpen?
Yes. Simple triggers can write cells. Restricted services still need installable triggers and authorization.
How do I set value and note together?
Use setValue for the cell and setNote on the range for a comment. They are separate calls.

Related Tutorials

Watch how setValue works

Browse more tutorials
Embed a Number in a Website from a Google Sheet

Embed a Number in a Website from a Google Sheet

Ever wanted to display some data from a google sheet on your site? Witho...
Send a Button from Google Sheets in an Email

Send a Button from Google Sheets in an Email

quick fun video to show you how to add a button to emails when you send ...
MAKE Your Google Sheets Add-on WORK

MAKE Your Google Sheets Add-on WORK

In this section of the Add-on course we'll be making the apps script wor...
Curate Google Sheets Easily - Automatic Bookmarklet Maker

Curate Google Sheets Easily - Automatic Bookmarklet Maker

Curated sites, articles, and more web resources super easily into a Goog...
How do I reference a different spreadsheet in Apps Script?

How do I reference a different spreadsheet in Apps Script?

I'll show you how to get text from one spreadsheet file to another with ...
10 Google Sheets I Wish Someone Would Make

10 Google Sheets I Wish Someone Would Make

if you're looking for ideas on what sheets to make I think this video is...

Related blog posts

Guides that explain setValue in more depth.

Browse the blog

Related glossary terms

Done reading about setValue?

Membership unlocks 636+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.

Need this once

Jump to a free tool or a single tutorial for this topic.

Learning Sheets for real

Unlock the full library, generators, and templates with membership.