Selecting the last value of a column

前端 未结 23 1878
再見小時候
再見小時候 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:34

    It looks like Google Apps Script now supports ranges as function parameters. This solution accepts a range:

    // Returns row number with the last non-blank value in a column, or the first row
    //   number if all are blank.
    // Example: =rowWithLastValue(a2:a, 2)
    // Arguments
    //   range: Spreadsheet range.
    //   firstRow: Row number of first row. It would be nice to pull this out of
    //     the range parameter, but the information is not available.
    function rowWithLastValue(range, firstRow) {
      // range is passed as an array of values from the indicated spreadsheet cells.
      for (var i = range.length - 1;  i >= 0;  -- i) {
        if (range[i] != "")  return i + firstRow;
      }
      return firstRow;
    }
    

    Also see discussion in Google Apps Script help forum: How do I force formulas to recalculate?

提交回复
热议问题