Home > Net >  My code in Apps script is taking too much time to execute
My code in Apps script is taking too much time to execute

Time:03-13

If the user sets value of C2 as Message Finder then my cell should go to c77. I have such say 9-10 cases. I have added 3 cases in the code.

But, it is taking too long and my sheet shows "Running script for more than 8-10 seconds.

My aim is to reduce it to just 1-2 seconds or at least better than current situation

function getTool() 
{
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Course");
  if(sheet.getRange("c2").getValue() == "Message Finder")
  {
  sheet.setActiveCell("Course!T95");
}
  else if(sheet.getRange("c2").getValue() == "Fee Finder")
  {
  sheet.setActiveCell("Course!U39");
}
 else if(sheet.getRange("c2").getValue() == "Fee Message")
  {
  sheet.setActiveCell("Course!N39");
}
}

Please help. Thanks

CodePudding user response:

Still see no big problem with your code.

Though probably you can speed up the code this way:

function getTool() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
  var cell = sheet.getRange('c2').getValue();

  if (cell == 'Message Finder') { sheet.getRange('t95').activate(); return }
  if (cell == 'Fee Finder')     { sheet.getRange('u39').activate(); return }
  if (cell == 'Fee Message')    { sheet.getRange('n39').activate(); return }
}
  • Related