title: Google Apps Script performing Index & Match function between two separate Google Sheets
body: <p>I am using Google Apps Script to perform a Index and Match function between two separate Google Sheets and retrieve the matching records and populate the designated sheet and column. Although it works fairly well, I would like to get the script to run more efficiently and as such use less time. Could Someone please look at the code example below and provide me with advice/pointers to do so</p>
  
  <pre><code>function SiteIDLookup() {
  var search_spreadsheet = SpreadsheetApp.openById("GoogleSheetId");
  SpreadsheetApp.setActiveSpreadsheet(search_spreadsheet);
  var find_spreadsheet = SpreadsheetApp.openById("GoogleSheetId");
  SpreadsheetApp.setActiveSpreadsheet(find_spreadsheet);
  var ssheet = search_spreadsheet.getSheetByName("schoolSiteID_Lookup");
  var fsheet = find_spreadsheet.getSheetByName("Info_Formatted");
  var FMaxR = fsheet.getMaxRows();
  fsheet.getRange(2, 16, FMaxR, 1).clear({contentsOnly: true});
  var findData = fsheet.getDataRange().getValues();
  var searchData = ssheet.getDataRange().getValues();
  
  for(var i=0; i &lt; findData.length; i++) {
   for(var j=0; j &lt; searchData.length; j++) {
    var find = findData[i][14];
    var searchref = searchData[j][0];
  
    if(find == searchref &amp;&amp; find != "" ) {
     var found = ssheet.getRange(j+1,2,1,1).getDisplayValue();
     fsheet.getRange(i+1,16,1,1).setValue(found);
     }
    }
   }
  }
  </code></pre>