So I have a google sheet document which houses figured for each hour of the day from 6 - 16:00 (each hour in a different tab.

I’m looking to add a script and a button that will allow me to clear all the cells on all sheets with one click, I managed to find help online which would clear what sheet, but when I tried to add in the other sheet names it wouldn’t work (o really have no clue about script or coding so that is my issue)

Essentially I need f2:aa86 clearing from all of the hourly tabs which are named “7:00” “8:00” “9:00” etc

Thanks for any help!

  • Hi and welcome. A question... you said initially said clear all the cells but later you refer to f2:aa86 clearing. What do you understand by the term f2:aa86 clearing?
    – Tedinoz
    Dec 21, 2021 at 3:14

1 Answer 1


You do need to learn how to write scripts OR, at the very least, how to adapt an existing script to your own circumstances. This answer is designed to provide a solution by referencing some existing scripts and also helping with referencing more information.

  • You want a button that will allow me to clear all the cells on all sheets with one click

  • You want to the script to work on all hourly tabs (6 - 16:00) which are named “7:00” “8:00” “9:00” etc_

  • You want to clear all the cells on each sheet. There's a command that does that: clearContents() and the documentation reference includes a code snippet Doc ref.

Putting this all together you might use these scripts:

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
      .addItem('Clear sheets', 'clearSheets')

function clearSheets() {
  var selectedSheets = ["6:00","7:00","8:00","9:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00"]; // select the sheets you want to run the function for
  var sheets = SpreadsheetApp.getActive().getSheets(); // get all sheets
  // iterate over all sheets and execute code on selectedSheets
      // Logger.log("Cleared contents - sheet:"+sheet.getName())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.