D
D
dpmain2020-12-06 13:18:47
Google Sheets
dpmain, 2020-12-06 13:18:47

How to implement cell range notifications in Google Sheets?

Guys, please help. There is such a script for google sheets:

var url = ' https://hooks.slack.com/services/ ';

function sampleName(e){
    
  var newValue = e.value; 
  var oldValue = e.oldValue; 
  var user = e.user; 
    
  var payload = {
      'text' : user + " Изменено с " + oldValue + " на "  + newValue  + " :wink:"
    };

  var params = {
      'method' : 'post',
      'contentType' : 'application/json',
      'payload' : JSON.stringify(payload)
    };
 return UrlFetchApp.fetch(url, params)


Now it works so that any change in the table sends a change notification to the Slack messenger.

But I need to make sure that only in a certain range the script fires, for example: the value in cell B5 is changed, and only then the notification is sent to Slack. How can this be implemented in the current script? I will be very grateful. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2020-12-06
@dpmain

The simplest is to check the cell address

function sampleName(e){
  // Если изменилась ячейка B5 пользователем
  if (e && e.range && e.range.getColumn() == 2 && e.range.getRow() == 5) { 
    // тут все делается
  }
}

Please note that the cell must be modified by the user!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question