How to run multiple onEdit functions in the same script (google Sheets)?

Asked

Viewed 936 times

0

I tried several ways and none worked.

I want a function that when someone types something, the cell content automatically becomes all uppercase and no accents.

E.g.: if I type "aaaauu", it immediately becomes "AEIOAAUU".

What I’ve already tried:

  1. change the accent letter to a letter without and then capitalize everything, all in the same onEdit;
  2. separate functions into different onEdit, in the same script;
  3. an onEdit calling functions in other scripts.

This is my code:

function onEdit(e){
  try{
    myA(e);
    myE(e);
    myUpper(e);
  }
  catch(e){
    if(e){}}
}

function myFunction(){
  var app= SpreadsheetApp;
  var targetSheet= app.getActiveSpreadsheet().getSheetByName("Sheet1");

  onEdit();
} 

The functions "Mya", "Mye" and "myUpper" are each in a separate script and they are:

function myUpper(e) {
   e.range.setValue(e.value.toUpperCase());
}

function myE(e) {
  e.range.setValue(e.value.replace(new RegExp("[[éèêëÉÈÊË]", 'g'),"E"));
}

function myA(e) {
  e.range.setValue(e.value.replace(new RegExp("[[áàâäãÁÀÂÄÃ]", 'g'),"A"));
}

Running the code, only the "Mye" function works. That is, only the letters "and" with accent become "E".

What am I doing wrong?

From now on, thank you very much.

1 answer

0


I solved with the following code:

function onEdit(e){
  var ss = e.source;
  var sheet = ss.getSheetByName('Sheet1');
  var value = e.value;
  var range = e.range;
  value = value.replace(new RegExp("[[éèêëÉÈÊË]", 'g'),"E");
  value = value.replace(new RegExp("[[áàâäãÁÀÂÄÃ]", 'g'),"A");
  value = value.toUpperCase();
  range.setValue(value);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.