I spent the last two nights without sleeping, because I can not solve this problem. I want to create a macro, where I change the page according to the information of a cell.
ScriptGoogle
Cell A1 = Month. (January or february or March, It is variable)
function ABC() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('A1'), true);
}
in Visual Basic (excel) we can do that using
Sub ABC()
Sheets([A1].Text).Select
End Sub
Please help me!
CodePudding user response:
Here is the funny script that immediately activates a sheet with the name taken from a current edited cell:
function onEdit(e) {
var sheet_name = e.value;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheet_name);
ss.setActiveSheet(sheet);
ss.toast('Jump to the ' sheet_name);
}
I don't know your workflow, I suspect it makes sense to limit the script by some range or/and some special syntax. Otherwise there will be surprises constantly.
CodePudding user response:
Move to the sheet named in A1
function ABC() {
SpreadsheetApp.getActive().getSheetByName(SpreadsheetApp.getActiveSheet().getRange("A1").getDisplayValue()).activate();
}