I have an Apps Script that is supposed to do run through the spreadsheet and if a company belongs to 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 < 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++;
}
}