I'm trying to create a function that loops through column "M" and multiplies each cell with a constant number (ex, 10.5). I finally managed to create a function that does this, but it takes time to execute and hits a runtime error before it finishes because it takes longer than 30 seconds to execute fully. Do you guys think it's possible to speed up my code somehow? Would appreciate if anyone could point me in the right direction. Below is my code.
function onEdit(e) {
var ss = e.source;
var cell = e.range;
if(cell.getRow() == 1 && cell.getColumn() == 13 && e.value != null){
if (cell.getDisplayValue() == 'Currency EURO') {
var valuta = 10.5;
}
if (cell.getDisplayValue() == 'Currency Pund') {
var valuta = 12.31;
}
var range = ss.getRange("M:M");
var count = range.getDisplayValues();
for(var i=2;i<count.length;i++){
ss.getRange("M"+ i).setValue(Number(ss.getRange("M"+ i).getDisplayValue())*valuta);
}
}
}