checkbox

Inserting check boxes in Google sheets

A checkbox that permits the user can create binary choice. Like user can select choice between two options; options are yes or No. Checkboxes in Google Sheets is a new feature; You can add boxes to cells in a spreadsheet easily.  Checkboxes have shown as ☐ when unchecked, or ☑ when checked. Checkboxes can be used for multi-purpose. For tracking project, taking attendance and so on. Steps of inserting checkboxes are following:

Firstly, on your computer, open a spreadsheet in Google sheet  
You can check Google sheets templates in feature image in case of any confusion.

Secondly, select the cells you want to have check boxes

Thirdly, in the menu at the top, click Insert->Checkbox.

Moreover, to remove checkboxes, select the boxes you want to remove and press Delete.

App script to insert checkboxes

However, you can use app script to insert checkboxes, SpreadsheetApp class has new data validation() and requireCheckbox() methods which can be used.

Firstly, create a data validation rule. And apply that rule to any cell or range where you want to insert checkboxes.

Data validation rule
var checkboxes = SpreadsheetApp.newDataValidation().requireCheckbox().setAllowInvalid(false).build();

Secondly Apply validation to range A1: A10 and set values. As true if you want all checkboxes by default checked or false if you want all unchecked.

sh.getRange('A1:A10').setDataValidation(checkboxes).setValue(true);

Complete code snipped which is inserting checkboxes in cells A1:A10, you can set any other range or cell where you want to have check boxes.

function insertCheckbox(){

    var ss=SpreadsheetApp.getActiveSpreadsheet();
    var sh=ss.getActiveSheet(); //Active Sheet
    
    //Data Validation Rule
    var checkboxes = SpreadsheetApp.newDataValidation().requireCheckbox().setAllowInvalid(false).build();

    //Set validation with checkboxes all checked

    sh.getRange('A1:A10').setDataValidation(checkboxes).setValue(true);

}

Consequently, now you are able to insert checkboxes in google sheets app. However, if you have any query regarding this you can ask through comment.

One Response

Add a Comment

Your email address will not be published. Required fields are marked *