I am trying to clear data from multiple sheets. I have a code that works for the current active sheet and data ranges I need, but I can not for the life of me figure out how to make it clear the same data from multiple sheets. Here is the code:
// This section adds the top menu
function onOpen() {
SpreadsheetApp.getUi().createMenu('Reset')
.addItem("Formulas Only", "ResetFormulas")
.addItem("Entire Page", "ResetPage")
.addToUi()
}
// This section makes a button to reset the whole page copies the entire page
function ResetPage() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Data1'); // Enter tab name of what you’re copying from
sheet.getRange('A1:U39').copyTo(ss.getRange('A1:U39')) //enter entire tab range
}
// This section copies only the cells you specify
function ResetFormulas() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet12'); // Enter tab name here of what you’re copying
from
//Header
sheet.getRange('B6:E20').copyTo(ss.getRange('B6:E20')) //first range you’re copying
sheet.getRange('N6:Q20').copyTo(ss.getRange('N6:Q20')) //next range
sheet.getRange('B25:E39').copyTo(ss.getRange('B25:E39')) //etc
sheet.getRange('N25:Q39').copyTo(ss.getRange('N25:Q39')) //you get it
}
What specifically would I change to make it clear multiple sheets rather than the active one?
EDIT:Solved I figured it out... at least a way that accomplishes what I am after. If anyone else is looking to do the same thing here is the code that did it. I ONLY use the ResetFormulas part of the function not the ResetPage. This only works if you have the same exact sheet multiple times that you want to clear specific data from. You will need a protected master sheet that you label in the script, mine was "Sheet 12". This is what will be copied and will replace the ranges you specify from each sheet that you specify. I don't know if everything is needed or if there is an easier way, I don't know anything about scripts or code, this is from hours of looking at other examples and just typing stuff till it worked.
// This section adds the top menu
function onOpen() {
SpreadsheetApp.getUi().createMenu('Reset')
.addItem("Formulas Only", "ResetFormulas")
.addItem("Entire Page", "ResetPage")
.addToUi()
}
// This section makes a button to reset the whole page copies the entire page
function ResetPage() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(''); // Enter tab name of what you’re copying from
sheet.getRange('').copyTo(ss.getRange('')) //enter entire tab range
}
// This section copies only the cells you specify
function ResetFormulas() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet 12'); // Enter tab name here of where you are copying from.
//The sheet,getRange(cellsyouwantcopied) copies the cells you want from your master sheet. The copyTo(ss.getsheetByName('Yoursheetnamehere').getRange(cellstobecopied) is where you type the sheet name and same range you want to be copied over
sheet.getRange('B6:E21').copyTo(ss.getSheetByName('Sign Pricing').getRange('B6:E21'))
sheet.getRange('N6:Q21').copyTo(ss.getSheetByName('Sign Pricing').getRange('N6:Q21'))
sheet.getRange('B25:E40').copyTo(ss.getSheetByName('Sign Pricing').getRange('B25:E40'))
sheet.getRange('N25:Q40').copyTo(ss.getSheetByName('Sign Pricing').getRange('N25:Q40'))
sheet.getRange('B44:E59').copyTo(ss.getSheetByName('Sign Pricing').getRange('B44:E59'))
sheet.getRange('P53').copyTo(ss.getSheetByName('Sign Pricing').getRange('P53'))
}
Repeat the section "sheet.getRange().copyTo..." for as many sheets or ranges that you need cleared.
I am trying to clear data from multiple sheets.
? – Tanaikesheet.getRange('A1:U39').copyTo(ss.getRange('A1:U39'))
? If so, please see my answer below. – ziganotschka