【问题标题】:How Can I use a custom function's range without Quotation?如何在没有引号的情况下使用自定义函数的范围?
【发布时间】:2022-10-18 20:17:29
【问题描述】:

我想使用=GETLASTROW(A1:A10)

而不是=GETLASTROW("A1:A10")

我想获取具有值的特定范围的最后一行编号...

这是我的自定义函数 你能更新这个吗?

/**
 * Get the last row counts with the blank cells included for a specific range selected.
 *
 * @param {A1:A10} range -->Enter the column number to count on.
 * 
 * @customfunction
 */



function GETLASTROW(range) {
  var ss = SpreadsheetApp.getActive().getActiveSheet();

  var rg = ss.getRange(range).getValues();
  var lrindex;

  for(var i = rg.length-1;i>=0;i--){
    lrindex = i;

    if(!rg[i].every(function(c){ return c == ""; })){
      break;
    }
  }
  return lrindex + 1;
}

如果您这样做了,请回复我更新我的代码...

【问题讨论】:

    标签: javascript google-sheets javascript-objects spreadsheet


    【解决方案1】:

    欢迎来到 SO,你不能像这样使用它 GETLASTROW(A1:A10) 这里 A1:A10 不是 JS 知道的类型,你需要使用 JavaScript 类型,如 String, Array, Object,我认为 objects 是最适合你的东西例如,您可以像这样调用函数GETLASTROW({A1:"A10"})

    然后你可以像这样使用它

    GETLASTROW({A1:"A10"})
    
    function GETLASTROW(rangeObject){
       var range = rangeObject["A1"] // the value of this will be A10
    }
    

    【讨论】:

    • 对不起,我不明白..你能用它更新我的代码然后我想我可以使用 =GETLASTROW(A1:A10) 而不是 =GETLASTROW("A1:A10")
    猜你喜欢
    • 2020-06-24
    • 2023-04-07
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    相关资源
    最近更新 更多