I am using a number of sheets and want to force my script to go to a specific sheet but instead it stays on the active sheet that was just created in my script ?
Note: I do not want to use the URL but the actual name of the spread sheet instead, and think I have to use the setActiveSheet() but have not been able to find any information but that it does not use a string but instead you have to use the object from the parent class ?
The script is showing in the log the word "Master_Approval" and is the wrong sheet the name of the active sheet.
var Sprsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = Sprsheet.getActiveSheet();
var mySheet = sheet.getSheetName();
if (sheet.getSheetName() == "2020Members") {
Logger.log('THE ACTIVE SHEETS NAME is :' + mySheet);
}
else {
Logger.log('THE WRONG ACTIVE SHEETS NAME is :' + mySheet);
// Force to the correct sheet !
var sheetDataAsArr = sprSheet.getSheetByName("2020Members");
var sheet = sprSheet.getActiveSheet();
var mySheet = sheet.getSheetName();
Logger.log('THE ACTIVE SHEETS NAME is :' + mySheet);
}
It should show the "2020Members" but is not and if the test fails I want to force the active sheet to be "2020Members" and not the sheet we are in currently.
var sheetDataAsArr = sprSheet.getSheetByName("2020Members");
var mainSheet = sheetDataAsArr.getActiveSheet();
Logger.log('THE ACTIVE is :' + mainSheet);
var sheet = sprSheet.setActiveSheet(mainSheet);
var mySheet = sheet.getSheetName();
Logger.log('THE ACTIVE SHEETS NAME is :' + mySheet);
What is wrong above?