sheetsquestions
sheetsquestions

Reputation: 77

Query function to get last row in Google Sheets

I have a sheet where data is updated daily.

however, the last integer often ends in between row 131 to 133.

how do I run a query function to display the last integer in row 1 column C?

I cannot do a simple =A131 on C1 because it can be on A133 the next day.

1 1

images: https://i.sstatic.net/eJAAF.jpg

Upvotes: 4

Views: 12231

Answers (2)

Tedinoz
Tedinoz

Reputation: 7949

This is a simplified version of my original code.

The value of the last integer and the row number are output for user information.

The code copes with dates, text, pseudo-value text (37*2), and decimals.


function so5754079102() {

  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheetname = "Sheet1";
  var sheet = ss.getSheetByName(sheetname);
  var Avals = ss.getRange("A1:A").getValues();
  var Alast = Avals.filter(String).length;
  Logger.log("Last row = "+Alast);
  var data = sheet.getRange(1,1,Alast,1).getValues();
  for (var i = Alast-1;i>=0;i--){
    Logger.log("i = "+i+", data 1 ="+data[i][0]+", and parse data 1 = "+parseInt(data[i][0], 10));
    if (data[i][0] === parseInt(data[i][0], 10)){
      break; 
    }
  }
  sheet.getRange("D1").setValue(+(i+1));
  sheet.getRange("D2").setValue(data[i][0]);
}

Screenshot

Screenshot

Upvotes: 0

player0
player0

Reputation: 1

paste in C1 cell:

=QUERY(A1:A, "offset "&COUNTA(A1:A)-1, 0)

0

Upvotes: 4

Related Questions