How to Add Radio Buttons to Google Sheets (2024 Update)

Video google sheet radio button

In this article, we’ll show you how to give a list of checkboxes the same functionality as radio buttons in Google Sheets using Apps Script. Are you ready to level up your Google Sheets game? Let’s dive in!

Formatting the Sheet and Adding Checkboxes

The first step is to format the sheet and add checkboxes to the process. Here’s an example of a sheet where we’ll be adding checkboxes to the range B2:E6.

Google Sheets Checkbox

To add the checkboxes, select the range and click on Insert, then select Checkboxes. Voila! The checkboxes are now inserted.

By default, you can check multiple checkboxes on the same row simultaneously. However, we want to change this behavior using a custom script, so that when a new checkbox on the same row is checked, Google Sheets will automatically uncheck the other checkboxes. This will give us the same functionality as radio buttons in our Google Sheet.

Inserting the Script

To insert the script, follow these steps:

  1. Click on Extensions, and then select Apps Script.
  2. A new window will load, containing Google Apps Script.

Copy the following script from Ben Collins and paste it into the code editor:

function onEdit(e) {
  var sheet = e.range.getSheet();
  if (sheet.getName() == 'Sheet Name') {
    if (e.range.getColumn() >= 2 && e.range.getColumn() <= 5) {
      var row = e.range.getRow();
      var values = sheet.getRange(row, 2, 1, 4).getValues();
      for (var i = 0; i < values[0].length; i++) {
        if (i != e.range.getColumn() - 2) {
          sheet.getRange(row, i + 2).uncheck();
        }
      }
    }
  }
}

Replace 'Sheet Name' with the name of your sheet, and 2 and 5 with the columns of your checkbox range.

Next, click on the Save Project button to save the project.

Running the Script

Now we can run the script:

  1. Click on Run > Run function > onEdit.
  2. The Execution log will appear, and you’ll see an error. Don’t worry, this is normal.

Using the Sheet

Go back to the tab with your Google Sheet and start checking the checkboxes. Notice that when you check another checkbox on the same row as a previously checked checkbox, the previously checked one will be automatically unchecked. Pretty neat, right?

Congratulations! You’ve successfully implemented the script.

FAQs

What if I only have three choices per row?

Let’s say you want to add choices in columns B, C, and D only. You just need to make a slight modification to the script. You can copy the script below:

function onEdit(e) {
  var sheet = e.range.getSheet();
  if (sheet.getName() == 'Sheet Name') {
    if (e.range.getColumn() >= 2 && e.range.getColumn() <= 4) {
      var row = e.range.getRow();
      var values = sheet.getRange(row, 2, 1, 3).getValues();
      for (var i = 0; i < values[0].length; i++) {
        if (i != e.range.getColumn() - 2) {
          sheet.getRange(row, i + 2).uncheck();
        }
      }
    }
  }
}

Replace 'Sheet Name' with the name of your sheet, and 2 and 4 with the columns of your checkbox range.

You can copy the script from this link.

And here’s the result:

Example Results

What if the checkboxes are in different columns?

In that case, you’ll need to modify the script itself. Check out the following link for a guide on how to modify the script to accommodate checkboxes in other columns: Modify the Script for Checkboxes in Google Sheets

We hope this article has helped you better understand how to add radio buttons in Google Sheets. If you’re interested in learning more, check out our articles on how to create a button in Google Sheets and how to use named ranges in Google Sheets.

For more helpful articles and tips, visit Crawlan.com – your go-to source for all things Google Sheets!

Note: This article has been adapted and translated for bolamarketing.com, and adheres to E-A-T (Expertise, Authoritativeness, Trustworthiness, Experience) and YMYL (Your Money or Your Life) standards.

Related posts