I have this script:
function onEdit2(e) {
const sheetName = "Charts"; // Please set your sheet name.
const dropDownCell = "B4:B6"; // Please set the range of dropdown list.
var spreadsheet = SpreadsheetApp.getActive();
var cell = spreadsheet.getActiveCell();
var cellR = cell.getRow();
var cellC = cell.getColumn();
var cellValue = cell.getValue();
if (cellR == 4 && cellC == 2) {
spreadsheet.getRange('B6').clearContent();
spreadsheet.getRange('B6').setValue('⚠️ SELECT');
}
}
I would like to make it work only on Charts tab without affecting any other tab. Right now script works in all tabs.
CodePudding user response:
Actually the code doesn't make much sense to me. Here's what it boils down to:
function onEdit2(e) {
const sh = e.range.getSheet();
if(sh.getName() == "Charts" && e.range.columnStart == 2 && e.range.rowStart == 4) {
sh.getRange('B6').setValue('⚠️ SELECT');
}
}
CodePudding user response:
function onEdit2(e) {
const sheetName = "Charts"; // Please set your sheet name.
if( e.range.getSheet().getName() === sheetName ) {
const dropDownCell = "B4:B6"; // Please set the range of dropdown list.
var spreadsheet = SpreadsheetApp.getActive();
var cell = spreadsheet.getActiveCell();
var cellR = cell.getRow();
var cellC = cell.getColumn();
var cellValue = cell.getValue();
if (cellR == 4 && cellC == 2) {
spreadsheet.getRange('B6').clearContent();
spreadsheet.getRange('B6').setValue('⚠️ SELECT');
}
}
}