kensuke1984
kensuke1984

Reputation: 995

Does Google spread sheet have a function to obtain the row/column of the current active cell?

Excel allows to obtain the row/column of the current active cell by using a function Cell('row') or Cell('col'). which gives the row/column value of the last edited cell.

In Spreadsheet, the function CELL is different from that of Excel. Two arguments are required in Spreadsheet. One is same as Excel ('row', 'column'...) and the other is the target cell.

Does SS have a function which gives the value of row/col Active cell?

Upvotes: 0

Views: 916

Answers (1)

Iamblichus
Iamblichus

Reputation: 19319

You can get the row and column indexes of the top-left cell of a range by doing Range.getRow() and Range.getColumn().

You can get the currently selected Range via getActiveRange().

Also, if the Range is multi-celled, you can get the range dimensions via Range.getNumRows() and Range.getNumColumns().

Using all this, if you want to select the full row/s of the currently selected cell/range, you can do the following:

function selectFullRow() {
  const activeRange = SpreadsheetApp.getActiveRange();
  const rowIndex = activeRange.getRow();
  const numRows = activeRange.getNumRows();
  const row = activeRange.getSheet().getRange(`${rowIndex}:${numRows+rowIndex-1}`);
  SpreadsheetApp.setActiveRange(row);
}

Finally, if you want to trigger this when you select a new cell, you can use onSelectionChange trigger.

Upvotes: 1

Related Questions