ray an
ray an

Reputation: 1288

Trigger a function on selecting a cell

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.

Upvotes: 3

Views: 5492

Answers (2)

gary
gary

Reputation: 21

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.

Upvotes: 2

Wicket
Wicket

Reputation: 38425

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?

Upvotes: 1

Related Questions