Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets API v4 - How to get the last row with value?

How to get the last row with value in the new Google Sheets API v4 ?

i use this to get a range from a sheet:

mService.spreadsheets().values().get("ID_SHEET", "Sheet1!A2:B50").execute();

how to detect the last row with value in the sheet ?

like image 399
seba123neo Avatar asked May 19 '16 18:05

seba123neo


People also ask

How do you find the last value in a row in Google Sheets?

To find the last value (number) in each row, you can use this formula as an alternative to the above formula. Here the Lookup syntax is as below. The search_key here is 1 and the search_range is =ArrayFormula(B2:F2/B2:F2) which returns the below values. DIV/0!

How do you find the last non empty row in Google Sheets?

The answer is =INDEX(B3:B,COUNTA(B3:B)) . Here is the explanation: COUNTA(range) returns number of values in a range, we can use this to get the count of rows.

How do I get the last value in a Vlookup in Google Sheets?

As I have mentioned, in Vlookup we can use a virtual 'range' (expression). As per my example, the physical range is A2:B. We can extract the last record from each group from this range and use that as a virtual range in Vlookup. That's the key logic that I am using here.


2 Answers

You can set the range to "A2:D" and this would fetch as far as the last data row in your sheet.

like image 57
A Paracha Avatar answered Sep 19 '22 12:09

A Paracha


I managed to get it by counting the total rows from current Sheets. Then append the data to the next row.

rowcount = this.mService.spreadsheets().values().get(spreadsheetId, range).execute().getValues().size()
like image 40
hellilyntax Avatar answered Sep 21 '22 12:09

hellilyntax