My code is a scheduler that makes a user sign-up to a particular slot in a particular sheet. The problem is that the code works only on the first sheet ("Jan 20 Mon").
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("Jan 20 Mon");
var sheet2 = ss.getSheetByName("Jan 21 Tue");
var sheet3 = ss.getSheetByName("Jan 22 Wed");
var sheet4 = ss.getSheetByName("Jan 23 Thurs");
var sheet5 = ss.getSheetByName("Jan 24 Fri");
var condition1as1 = sheet1.getRange("B2").getValue(); var condition1bs1 = sheet1.getRange("C2").getValue(); var condition1cs1 = sheet1.getRange("D2").getValue(); var condition1ds1 = sheet1.getRange("E2").getValue();
var condition1as2 = sheet2.getRange("B2").getValue(); var condition1bs2 = sheet2.getRange("C2").getValue(); var condition1cs2 = sheet2.getRange("D2").getValue(); var condition1ds2 = sheet1.getRange("E2").getValue();
var condition1as3 = sheet3.getRange("B2").getValue(); var condition1bs3 = sheet3.getRange("C2").getValue(); var condition1cs3 = sheet3.getRange("D2").getValue(); var condition1ds3 = sheet1.getRange("E2").getValue();
var condition1as4 = sheet4.getRange("B2").getValue(); var condition1bs4 = sheet4.getRange("C2").getValue(); var condition1cs4 = sheet4.getRange("D2").getValue(); var condition1ds4 = sheet1.getRange("E2").getValue();
var condition1as5 = sheet5.getRange("B2").getValue(); var condition1bs5 = sheet5.getRange("C2").getValue(); var condition1cs5 = sheet5.getRange("D2").getValue(); var condition1ds5 = sheet1.getRange("E2").getValue();
if (condition1cs1 == "1" && condition1ds1 == "None") {
var response = Browser.msgBox("PLEASE RECHECK SCHEDULE AND TID.", condition1as1+" , "+condition1bs1+" Are you sure?", Browser.Buttons.YES_NO);
if (response == "yes") {
sheet1.hideRows(2,1);
sheet1.getRange('E2').setValue("1");
//insert msgBox here
} else {
Browser.msgBox("Input again.");
}
}
if (condition1cs2 == "1" && condition1ds2 == "None") {
var response = Browser.msgBox("PLEASE RECHECK SCHEDULE AND TID.", condition1as2+" , "+condition1bs2+" Are you sure?", Browser.Buttons.YES_NO);
if (response == "yes") {
sheet2.hideRows(2,1);
sheet2.getRange('E2').setValue("1");
//insert msgBox here
} else {
Browser.msgBox("Input again.");
}
}
}
Basically, I tried to set-up all the sheets I am working with so I could access them anytime. The first if is for the first sheet (and it works). The second if is for the second sheet (and it doesn't work).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…