Answer the question
In order to leave comments, you need to log in
How to link to previous sheet in Google Sheets?
Good afternoon. Tell me, please, how can I refer to the previous sheet (not manually select it, but automatically)?
When creating a new sheet, I want it to take data from the previous sheet (from the same cells).
Answer the question
In order to leave comments, you need to log in
Get the index of the current sheet:
const ss = SpreadsheetApp.getActiveSpreadsheet()
const sheet = ss.getActiveSheet();
const index = sheet.getIndex();
ss. getSheets()[index - 2];
function getListPrev(range) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const index = sheet.getIndex();
const formula = sheet.getActiveRange().getFormula();
range = formula.match(/getListPrev\(([^\)]*?)\)/i)[1].trim();
const sheet_prev = (ss.getSheets()[index - 2] || null);
if (!sheet_prev)
throw new Error('Нет предыдущего листа!');
return sheet_prev
.getRange(range)
.getValues();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question