2017-12-04 6 views
0
私はこのコードで助けを探しています

自動日付テキスト「YES」

列12は、任意の値が含まれている場合、コードは、現在の日付を追加して
function onEdit() { 

    var s = SpreadsheetApp.getActiveSheet(); 

    if(s.getName() == "Trip Overview") { //checks that we're on the correct sheet 

    var r = s.getActiveCell(); 

    if(r.getColumn() == 12) { //checks the column 

     var nextCell = r.offset(0, 15); 

     //if(nextCell.getValue() !== ) //is empty? 

     nextCell.setValue(new Date()); 
    } 
    } 
} 

、1,2,3または"はい" "adf" "いいえ"など

セル12に "はい"が含まれている場合のみ、このコードを修正して日付を追加する方法はありますか?

答えて

0

正しいシートと列にあるかどうかをチェックした後、あなたは、セルの値が「YES」であれば() `のonEditで

function onEdit() { 

    var s = SpreadsheetApp.getActiveSheet(); 

    if(s.getName() == "Trip Overview") { //checks that we're on the correct sheet 

    var r = s.getActiveCell(); 

    if(r.getColumn() == 12) { //checks the column 

     if(r.getValue() == "YES") { //checksthe value of the cell 

     var nextCell = r.offset(0, 15); 

     nextCell.setValue(new Date()); 
     } 

    } 

    } 

} 
+1

チェックする必要があります'関数、あなたは本当に活用する必要がありますユーザが 'onEdit()'をトリガした場所とは異なる場所に移動したときに予期しない結果が発生するのを避けるために、 'getActiveCell()'を呼び出すのではなく、関数のパラメータとして提供されたEVENTを返します。 – Mogsdad

+0

ありがとうございました! –

関連する問題