How to get activated column's index in App Script?

Viewed 50
SpreadsheetApp.getActiveSheet().autoResizeColumn(activatedColumnIndex);

I want to get a current activated column index for auto-resizing cells by the column after editing is done in the sheet. I searched on this website and tried some few built-in functions but there's no functions such as getting current column index.

Is it possible to get a selected column index in App Script?

1 Answers

In your situation, how about the following sample script? In order to retrieve the current activated column number, I thought that SpreadsheetApp.getActiveRange().getColumn() might be able to be used.

Sample script:

const activatedColumnIndex = SpreadsheetApp.getActiveRange().getColumn();
SpreadsheetApp.getActiveSheet().autoResizeColumn(activatedColumnIndex);
  • In this case, when this script is run, the current activated column number is retrieved and the retrieved number is used for autoResizeColumn.

References:

Related