title: How to loop command using the .getRowIndex() in Google Sheets?
body: <pre><code>function getColIndexByName(colName) {
    var sheet = SpreadsheetApp.getActiveSheet();
    var numColumns = sheet.getLastColumn();
    var row = sheet.getRange(1, 1, 1, numColumns).getValues();
  for (i in row[0]) {
  var name = row[0][i];
  if (name == colName) {
    return parseInt(i) + 1;
      }
   }
      return -1;
     }
  
  function sendtoContacts () {
  
   var source = SpreadsheetApp.getActiveSpreadsheet();
   var ss = source.getActiveSheet();
   var row = ss.getActiveRange().getRowIndex();
  
   var group = ContactsApp.getContactGroup('From Googlesheet');
   var givenName = ss.getRange(row, getColIndexByName("First")).getValue();
   var familyName = ss.getRange(row, getColIndexByName("Last")).getValue();
   var email = ss.getRange(row, getColIndexByName("Work Gmail")).getValue();
   var Homeemail = ss.getRange(row, getColIndexByName("Personal Email")).getValue();
   var company = ss.getRange(row, getColIndexByName("Company")).getValue();
   var title = ss.getRange(row, getColIndexByName("Title")).getValue();
   var phone = ss.getRange(row, getColIndexByName("Phone")).getValue();
   var mobile = ss.getRange(row, getColIndexByName("Mobile")).getValue();
   var newContact =  ContactsApp.createContact(givenName, familyName, email);
   var contactid = newContact.getId();
   var addy = ss.getRange(row, getColIndexByName("Address")).getValue();
   var city = ss.getRange(row, getColIndexByName("City")).getValue();
   var prov = ss.getRange(row, getColIndexByName("Prov")).getValue();
   var pc = ss.getRange(row, getColIndexByName("Postal Code")).getValue();
   var address = addy + ", " + city + ", " + prov + ", " + pc
  
  
   var AltContact = ss.getRange(row, getColIndexByName("Alt Contact Name")).getValue();
   var AltRelation = ss.getRange(row, getColIndexByName("Alt ContactRelation")).getValue();
   var AltPhone = ss.getRange(row, getColIndexByName("Alt Contact Phone")).getValue();
   var AltWork = ss.getRange(row, getColIndexByName("Alt Contact Wk No")).getValue();
   var AltMobile = ss.getRange(row, getColIndexByName("Alt Contact Mobile")).getValue();
  
     newContact.addToGroup(group);
     newContact.addAddress("Home", address);
     newContact.addCompany(company, title);
     newContact.addEmail("Home", Homeemail);
     newContact.addCustomField("Emergency Contact", AltContact);
     newContact.addCustomField("Emergency Contact Relation", AltRelation);
     newContact.addCustomField("Emergency Contact Work", AltWork);
     newContact.addCustomField("Emergency Contact Mobile", AltMobile);
  
        for ( var i = 0; i &lt; phone.length ; i++){
           if (phone[i][3] != ''){ newContact.addPhone("HOME", phone); return}};   
  
        for ( var i = 0; i &lt; mobile.length ; i++){
           if (mobile[i][44] != ''){ newContact.addPhone("Mobile", mobile); return}};
  
          }
  
  
    function MakeAllContacts() {
     var source = SpreadsheetApp.getActiveSpreadsheet();
     var ss = source.getActiveSheet();
     var startRow = 2;  // First row of data to process
     var numRows = 100;   // Number of rows to process
  
  
     for (row = 2; row &lt; 6; row++)
     {
  
        sendtoContacts();
  
         }
      return
        }
  </code></pre>
  
  <p>Here I am duplicating the entries with MakeAllContacts() but I want to make the RowIndex change to every row in the sheet so it add all the contacts in the sheet.  Here is at Video I made explaining it <a href="http://goo.gl/Up4FN1" rel="nofollow">Video</a> and here is a link to my actual sheet <a href="http://goo.gl/4RcJMX" rel="nofollow">Google Sheet</a>.  I have a fair bit of code I would like to start sharing if I could just get my head are around looping instead of the one row to be All the rows in the sheet.  Thanks for any help is appreciated.</p>