Selecting the last value of a column

前端 未结 23 1886
再見小時候
再見小時候 2020-11-28 19:15

I have a spreadsheet with some values in column G. Some cells are empty in between, and I need to get the last value from that column into another cell.

Something li

23条回答
  •  一生所求
    2020-11-28 19:39

    I was playing with the code given by @tinfini, and thought people might benefit from what I think is a slightly more elegant solution (note I don't think scripts worked quite the same way when he created the original answer)...

    //Note that this function assumes a single column of values, it will 
    //not  function properly if given a multi-dimensional array (if the 
    //cells that are captured are not in a single row).
    
    function LastInRange(values) 
    {
      for (index = values.length - 1; values[index] == "" && index > 0; index--) {}
      return String(values[index]);
    }
    

    In usage it would look like this:

    =LastInRange(D2:D)
    

提交回复
热议问题