Script for recording a country in which a company belongs I have an Apps Script that is supposed to run through the spreadsheet, and if a company belongs to a certain country (there's a country column), set the value of the region row to something (e.g. Africa).

The spreadsheet has more than 8500 rows and this is the dirty code I have.  It's working, but if there's a better way to write it, I'd appreciate any pointers:

function setRegions() {
      var mySheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var myCompany = mySheet.getDataRange().getValues();
      var start = 2;
      for(i = 1; i &lt; myCompany.length; i++){
        var univ = myCompany[i];
        var country_code = univ[4];
        if (country_code == "ke" || 
            country_code == "ng" || 
            country_code == "ug" || 
            country_code == "za" ||
            country_code == "sn" ||
            country_code == "gh") {
          rgMyRange = mySheet.getRange("M" + start);
          rgMyRange.setValue("AFRICA");
        }else if (country_code == "eg" ||
                 country_code == "sa" ||
                 country_code == "ma"){
          rgMyRange = mySheet.getRange("M" + start);
          rgMyRange.setValue("MENA");
        }else if (country_code == "br" ||
                 country_code == "ar" ||
                 country_code == "mx" ||
                 country_code == "pe" ||
                 country_code == "co"){
          rgMyRange = mySheet.getRange("M" + start);
          rgMyRange.setValue("LATAM");
        }else if (country_code == "my" ||
                 country_code == "th" ||
                 country_code == "id" ||
                 country_code == "ph"){
          rgMyRange = mySheet.getRange("M" + start);
          rgMyRange.setValue("APAC");
        }else if (country_code == "in") {
          rgMyRange = mySheet.getRange("M" + start);
          rgMyRange.setValue("IN");
        }
        start++;
      }
    }
TL;DR : My comments won't improve the performances much. Also, I've never used Apps Script.

This being said, here what I did : I decided to change details to make your code more concise (removing variables used only once for instance).

function setRegions() {
      var mySheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var myCompany = mySheet.getDataRange().getValues();
      for(i = 1, start = 2; i &lt; myCompany.length; i++, start++){
        var country_code = myCompany[i][4];
        if (country_code == "ke" || 
            country_code == "ng" || 
            country_code == "ug" || 
            country_code == "za" ||
            country_code == "sn" ||
            country_code == "gh") {
          mySheet.getRange("M" + start).setValue("AFRICA");
        }else if (country_code == "eg" ||
                 country_code == "sa" ||
                 country_code == "ma"){
          mySheet.getRange("M" + start).setValue("MENA");
        }else if (country_code == "br" ||
                 country_code == "ar" ||
                 country_code == "mx" ||
                 country_code == "pe" ||
                 country_code == "co"){
          mySheet.getRange("M" + start).setValue("LATAM");
        }else if (country_code == "my" ||
                 country_code == "th" ||
                 country_code == "id" ||
                 country_code == "ph"){
          mySheet.getRange("M" + start).setValue("APAC");
        }else if (country_code == "in") {
          mySheet.getRange("M" + start).setValue("IN");
        }
      }
    }


Then, you can get rid of the different tests on the country_code by storing what you want in a dictionary :

function setRegions() {
      var dict = {
          "ke" : "AFRICA",
          "ng" : "AFRICA",
          "ug" : "AFRICA",
          "za" : "AFRICA",
          "sn" : "AFRICA",
          "gh" : "AFRICA",
          "eg" : "MENA",
          "sa" : "MENA",
          "ma" : "MENA",
          "br" : "LATAM",
          "ar" : "LATAM",
          "mx" : "LATAM",
          "pe" : "LATAM",
          "co" : "LATAM",
          "my" : "APAC",
          "th" : "APAC",
          "id" : "APAC",
          "ph" : "APAC",
          "in" : "IN",
      };
      var mySheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var myCompany = mySheet.getDataRange().getValues();
      for(i = 1, start = 2; i &lt; myCompany.length; i++, start++){
        var country_code = myCompany[i][4];
        if (dict[country_code])
        {
          mySheet.getRange("M" + start).setValue(dict[country_code]);
        }
      }
    }