简体   繁体   English

带有 if else 语句的 For 循环 Google-apps-script

[英]For loop with an if else statement Google-apps-script

I have sheet.我有单子。 In column AI have simbol ☑ in some cells.在列 AI 中,某些单元格中有 simbol ☑。 I need that active cell moves to cell after last cell with ☑ simbol.我需要使用 ☑ simbol 将活动单元格移动到最后一个单元格之后的单元格。 Now code doesn't work as I want.现在代码无法正常工作。 Please help me to change code.请帮我更改代码。 Thanks.谢谢。

Here is my code这是我的代码

 function LastCellInCollA() {
  var sheet = SpreadsheetApp.getActiveSheet()
  var cell = sheet.getRange(2, 1, 1, 1);
  var i
  sheet.setCurrentCell(cell);  
  for (i = 2; i < 146; i++)
    var valuei = sheet.getRange(i, 1, 1, 1).getValues();
  {
    if (valuei = "☑️") 
    {  
      sheet.setCurrentCell(sheet.getRange(i, 1, 1, 1));
      i = i + 1;
        }
  }
}

Is that checkmark an ASCII symbol or are you using the Google Sheet checkbox?该复选标记是 ASCII 符号还是您使用的是 Google Sheet 复选框?

If you are using the Google Sheet checkbox, then the following script may work for you.如果您使用的是 Google Sheet 复选框,那么以下脚本可能适合您。

The recommended way is to not hit the sheet in each loop.推荐的方法是不要在每个循环中击中纸张。 So the script does the math and goes directly to the relevant cell instead of going row-by-row.因此脚本会进行数学运算并直接转到相关单元格,而不是逐行进行。

function LastCellInCollA() {
  var sheet = SpreadsheetApp.getActiveSheet()
  var data = sheet.getRange('A2:A').getValues();
  var d = 0;
  while (data[d][0] == true) { d++; } // If you are using ASCII symbol, replace 'true' with the symbol
  var lastRow = d + 2;
  var cell = sheet.getRange(lastRow, 1);
  sheet.setCurrentCell(cell);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM