3

How to write a trigger which gets triggered everytime the user selects any cell. The trigger will call a function which would log the row number of the highlighted cell on Google Apps Scripts

I have already written a function which is doing that:

function getCell() {
  var app = SpreadsheetApp;
  var ss = app.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  //get the current highlighted cell
  var cell = sheet.getCurrentCell();

  //get the row number
  var row = cell.getRow(); 

  //log the value
  Logger.log(row);

}

But I don't know how to write the trigger. Currently, I have to run the script every time I click on some other cell.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
ray an
  • 1,132
  • 3
  • 17
  • 42

2 Answers2

2

strange, it worked the first time....

function onSelectionChange(e){
   Browser.msgBox('cell selection change');
}

maybe things have changed since the question was posted, but landed here.

gary
  • 21
  • 3
1

The available triggers are described on https://developers.google.com/apps-script/guides/triggers/. An alternative that could serve as a workaround is to use the "poll technique" described on How do I make a Sidebar display values from cells?

Rubén
  • 34,714
  • 9
  • 70
  • 166