Enter the same value in every cell of a Range in Google Sheets using Apps Script

I recently found out that there is a very easy way to enter the same value in every cell of a Range in Google Sheets using Apps Script.

All you have to do is select the range and then use the setValue() method of the Range object.

function setValueToEveryCellInRange() {
   var range = SpreadsheetApp.getActiveSheet().getRange(1,1,5,5);
   range.setValue("Hello");
}

The above code selects the range A1:E5 of the sheet that is active (i.e., the selected sheet in your spreadsheet) and enters the text "Hello" in every cell.

Screenshot of a Google Sheets spreadsheet.

Thanks for reading!

Sign up to be notified when I publish new content

By signing up you agree to the Privacy Policy & Terms.