function myFunction(input) {
var valuetobereturn =0 ;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheetByName("Mark-ups");
for (var row = 2; row <= 193; row = row + 1) {
//valuetobereturn = 0
if (input >= sh0.getRange(row,7).getValue() && sh0.getRange(row,8).getValue() ) {
valuetobereturn = sh0.getRange(row,9).getValue();
}
}
return valuetobereturn;
}
a) Parameter "input" is passed to function myFunction
b) which is then checked if it exists in range with sheet "Mark-ups"
c) from row 2 to row 193 for column 7
and column 8
d) it returns value as "valuetobereturn" if condition is satisfied
e) "exceeded maximum time"
ERROR to be resolved
When your showing script works if the maximum execution time for the script is large, from your showing script, I understand your expected result is as follows.
input
and whether the value of column "H" has a value (You want to check True and False?).valuetobereturn
is overwritten when the if statement is true. From this situation, you want to retrieve the value of column "I" of the last checked row.0
.If my understanding is correct, how about the following modification?
getValue
is used in the loop, the process cost will be high. I guessed that this might be the reason for your current issue. Ref (Author: me)When this is reflected in your script, how about the following modification?
function myFunction(input) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheetByName("Mark-ups");
// Retrieve the values from cells "G2:I193".
var values = sh0.getRange("G2:I193").getValues(); // or var values = sh0.getRange("G2:I" + sh0.getLastRow()).getValues();
// Retrieve the value of column "I" of the last checked row.
var res = values.findLast(([g, h]) => input >= g && h);
var valuetobereturn = res ? res[2] : 0;
// Return the result value.
return valuetobereturn;
}