Reputation: 1944
In a script I'm setting a range using a Named Range. I need to get the first row number, to use for setting vals in other cols.
The Named Range 'ASX_100' is Top5!A8:A107... so the first Row Number I need is 8, but as a script novice I can't find something online to help. My code so far:
const ui = SpreadsheetApp.getUi();
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sTop5 = ss.getSheetByName('Top5');
const rASX100 = ss.getRange('ASX_100'), iLen = rASX100.getNumRows();
// Get first sheet row number in range rASX100:
How should I go about this pls?
Upvotes: 1
Views: 2067
Reputation: 1987
Once you have the range (rASX100
), you can get its first row with the methods getRow() or getRowIndex():
const ui = SpreadsheetApp.getUi();
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sTop5 = ss.getSheetByName('Top5');
const rASX100 = ss.getRange('ASX_100'), iLen = rASX100.getNumRows();
// Get first sheet row number in range rASX100:
const firstRangeRow = rASX100.getRow();
For the last row, you can use getLastRow().
Upvotes: 1