Answer the question
In order to leave comments, you need to log in
How to write a script to create a new sheet based on cells for Google spreadsheets?
Good day, I'm not good at programming, but it is necessary that in Google spreadsheets, based on the range of cells ( B2:B16 ) in the sheet, for example, "Settings", new sheets were created with the names of these cells, and with a fixed formula in A1 (I will insert it myself). If the cell is empty, then the sheet should not be created. If the data from the cell is deleted, then such a sheet must also be deleted.
I searched on the Internet, but due to inexperience in writing scripts, I did not find anything sensible.
Answer the question
In order to leave comments, you need to log in
1) Make onEdit () a trigger to catch editing of the desired sheet and range
2) Check if the list of sheets matches the list in the range
3) Compensate for the difference in the lists. What is missing - add sheets, what has disappeared - delete.
Here is the stub code for onEdit ()
function _onEdit(e) {
let sheet = e.source.getActiveSheet();
let address = e.range.getA1Notation().toUpperCase();
var row = e.range.getRow();
let col = e.range.getColumn();
let newValue = e.value;
let oldValue = e.oldValue;
if ((-1 != whiteListSheetNames.indexOf(sheet.getName())) && (-1 != whiteListRangeNames.indexOf(address))) {
// Что-то делаем
};
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question