I am trying to simplify my google apps script code and increase its readability. To this end, instead of calling setActiveSheet() function each time I want to activate a new sheet in my code, I decided to write a function that does the job and just call that function and include the name of the sheet as an argument like this:
function setSheet (sheetName) {
var sheetName;
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName(sheetName));
var sheet = spreadsheet.getActiveSheet();
};
Then for example if I want to activate the sheet named "Students", I would write the following simple code:
setSheet("Students");
The above code won't work. Any help?
setActiveSheetso much that refactoring its usage even occurs to you. The only reason you need to change the active sheet is if you need to move the user's view, or the Sprreadsheet Service methods you want to use can only be called in the active sheet. For most, this is not the case. PS: it doesn't work is not a valid problem or issue description.