For a spreadsheet that contains several sheets, I have a script with which I can delete data in all sheets from certain ranges at the push of a button.
Now I have a main spreadsheet that is linked to several other spreadsheets (and the sheets they contain) (import range, queries, etc.).
Is it possible to delete data in certain ranges by script at the push of a button in the connected spreadsheets, whereby I would like to trigger this from the main spreadsheet?!
The data that is to be deleted from the sheets using the script is manual user input and therefore does not come from the main spreadsheet. The Ranges/Cells that should be deleted are different between Sheet 1.A and 1.B
Attached a graph for better understanding:
My script so far is:
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Delete User Input Data')
.addItem(
'Delete Data now',
'userActionResetMultipleSheetsByRangesAddresses'
)
.addToUi();
}
function userActionResetMultipleSheetsByRangesAddresses() {
var sheetNames = [
{ name: 'Sheet1.A', rangesAddressesList: ['Y3:AG99'] },
{ name: 'Sheet1.B', rangesAddressesList: ['AI3:AX99'] },
];
sheetNames.forEach(function(sn) {
var sheet = SpreadsheetApp.getActive().getSheetByName(sn.name);
if (sheet) {
resetByRangesList_(sheet, sn.rangesAddressesList);
}
});
}
function resetByRangesList_(sheet, rangesAddressesList) {
sheet.getRangeList(rangesAddressesList).clearContent();
}
SpreadsheetApp.openById()
for each id and loop through. Consult the official documentation. – TheMaster