此腳本被編寫爲在公司項目日誌中使用,以幫助保持跟蹤和舊作業的歷史記錄。使用if和if的onEdit腳本時遇到問題
所有的「if」和「else if」語句都按照他們的意圖工作,除了一個小小的snafu,我似乎無法查明,我希望有一些可以看到我明顯忽略了什麼。我天翻地覆的
例子:
說我對sheetName("Parking lot")
和我在列改一個名字(4),它會觸發我的「if
」聲明,這就是問題所在:它應該只被解僱了「if else
「與sheetName
相關聯。當我在sheetName("Waiting to be assigned")
上時,我只想要發表該聲明。
我也試過在我的聲明中使用ss.getName()
,這似乎沒有什麼區別。
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var newDate = Utilities.formatDate(new Date(), "PST", "M/d/yyyy");
var nonMemberTracking = memberTracking();
var currentSheet = ss.getSheetByName("Current Projects");
var currentRange = currentSheet.getRange(currentSheet.getLastRow() + 1, 1);
var currentColumnToWatch = 15;
var currentActiveCell = currentSheet.getActiveCell();
var currentRangez = currentSheet.getRange("A3:T");
var parkinglotSheet = ss.getSheetByName("Parking lot");
var parkinglotRange = parkinglotSheet.getRange(parkinglotSheet.getLastRow() + 1, 1);
var parkinglotColumnToWatch = 15;
var parkinglotActiveCell = parkinglotSheet.getActiveCell();
var completedSheet = ss.getSheetByName("Completed");
var completedRange = completedSheet.getRange(completedSheet.getLastRow() + 1, 1);
var completedColumnToWatch = completedSheet.getRange("O2:O").getValue();
var completedActiveCell = completedSheet.getActiveCell();
var waitingSheet = ss.getSheetByName("Waiting to be assigned");
var waitingColumnToWatch = 4;
var waitingActiveCell = waitingSheet.getActiveCell();
var waitingRange = waitingSheet.getRange(waitingSheet.getLastRow() + 1, 1);
currentRangez.sort([{ column : 4, ascending: true},{ column : 11, ascending: true}])
if(waitingActiveCell.getColumn() == waitingColumnToWatch && waitingActiveCell.getValue() !== ""){
currentSheet.insertRowAfter(currentSheet.getLastRow());
waitingSheet.getRange(waitingActiveCell.getRow(), 9, 1).setValue("YES");
waitingSheet.getRange(waitingActiveCell.getRow(), 1, 1, waitingSheet.getLastColumn()).moveTo(currentRange);
waitingSheet.deleteRow(waitingActiveCell.getRow());
currentSheet.sort(4);
} else if(currentActiveCell.getColumn() == currentColumnToWatch && currentActiveCell.getValue() == "Parking lot"){
parkinglotSheet.insertRowAfter(parkinglotSheet.getLastRow());
currentSheet.getRange(currentActiveCell.getRow(), 1, 1, currentSheet.getLastColumn()).moveTo(parkinglotRange);
currentSheet.deleteRow(currentActiveCell.getRow());
parkinglotSheet.sort(4);
} else if(currentActiveCell.getColumn() == currentColumnToWatch && currentActiveCell.getValue() == "Complete"){
completedSheet.insertRowAfter(completedSheet.getLastRow());
currentSheet.getRange(currentActiveCell.getRow(), 1, 1, currentSheet.getLastColumn()).moveTo(completedRange);
currentSheet.deleteRow(currentActiveCell.getRow());
completedSheet.sort(4);
nonMemberTracking;
} else if(parkinglotActiveCell.getColumn() == parkinglotColumnToWatch && parkinglotActiveCell.getValue() !== "Parking lot"){
currentSheet.insertRowAfter(currentSheet.getLastRow());
parkinglotSheet.getRange(parkinglotActiveCell.getRow(), 1, 1, parkinglotSheet.getLastColumn()).moveTo(currentRange);
parkinglotSheet.deleteRow(parkinglotActiveCell.getRow());
currentSheet.sort(4);
}}
謝謝,我會試試看。 –
這工作完美,再次感謝。 –