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!

Master Google Sheets Automation

Sign up to receive exclusive Automation tips and tutorials!
I'll send you actionable tips on automating tasks with Google Sheets and coding with Apps Script. You'll also be notified whenever new content is published.
PLUS: Get instant access to my Birthday Reminder Template! 🎂
By signing up you agree to the Privacy Policy & Terms.

Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!