Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 我正在使用依赖于相对列的If语句-无法使其工作_Google Apps Script_Google Sheets_Google Sheets Macros - Fatal编程技术网

Google apps script 我正在使用依赖于相对列的If语句-无法使其工作

Google apps script 我正在使用依赖于相对列的If语句-无法使其工作,google-apps-script,google-sheets,google-sheets-macros,Google Apps Script,Google Sheets,Google Sheets Macros,我正在使用谷歌表单。我在E1:AD1单元格中有复选框。选中其中一个复选框时,我希望该列第1行中的单元格的背景颜色为绿色 最终,我希望能够对列中的不同行执行相同的操作。请参阅下面我的onEdit脚本 /** @OnlyCurrentDoc */ function onEdit(e) { //This IF statement ensures that this onEdit macro only runs when cells E1:AD1 are edited in the sheet na

我正在使用谷歌表单。我在E1:AD1单元格中有复选框。选中其中一个复选框时,我希望该列第1行中的单元格的背景颜色为绿色

最终,我希望能够对列中的不同行执行相同的操作。请参阅下面我的onEdit脚本

/** @OnlyCurrentDoc */

function onEdit(e) {

//This IF statement ensures that this onEdit macro only runs when cells E1:AD1 are edited in the sheet named "Finances 2020"
if (
e.source.getSheetName() == "Finances 2020" &&
e.range.columnStart == 5 &&
e.range.columnEnd == 30 &&
e.range.rowStart >= 1 &&
e.range.rowEnd <= 1 
) { 

//This if statement checks if the checkbox was checked or unchecked:
var checkboxtest = e.range.getValue()
if (checkboxtest == true) {

  //If so, colour the cell in row 1 of that column as green:
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var Finances_2020 = spreadsheet.getSheetByName("Finances 2020");
  var Fortnightcolumn = e.range.columnStart      
  Finances_2020.getRange(1, Fortnightcolumn).setBackground('#d9ead3');

}else{

}
}
}
;
/**@仅限当前文档*/
功能OneEdit(e){
//此IF语句确保仅当在名为“Financials 2020”的工作表中编辑单元格E1:AD1时,才会运行此OneEdit宏
如果(
e、 source.getSheetName()=“财务2020”&&
e、 range.columnStart==5&&
e、 range.columnEnd==30&&
e、 range.rowStart>=1&&
e、 range.rowEnd
  • 如果要对第1行第5列和第30列之间的任何已编辑单元格应用背景更改,则正确的语句为:

if(e.source.getSheetName()==“Financials 2020”&&5完美!也感谢您的提示和建议-非常有用!!!很高兴它有帮助!
function onEdit(e) {
//This IF statement ensures that this onEdit macro only runs when cells E1:AD1 are edited in the sheet named "Finances 2020"
if (e.source.getSheetName() == "Finances 2020" &&
5<=e.range.getColumn()<=30 &&
e.range.getRow() == 1) { 
  //This if statement checks if the checkbox was checked or unchecked:
  var checkboxtest = e.range.getValue();
  if (checkboxtest == true) {
    //If so, colour the cell in row 1 of that column as green:
    e.range.setBackground('#d9ead3');
    }
  }
}