title: Data copying with Google Apps Script
body: <p>I am trying to write a script in Google Apps Script that takes cell information from one sheet and copies it to another sheet, both for just grabbing certain columns to display on the second sheet and also a condition based on the values inside cells in a certain column. Here is what I have so far:</p>
  
  <pre><code>function onMyEdit() {
    var myMaster    = SpreadsheetApp.openById("xxxxx");
    var masterSheet = myMaster.setActiveSheet(myMaster.getSheets()[0]);
    var myNames     = SpreadsheetApp.openById("xxxxx");
    var namesSheet  = myNames.setActiveSheet(myNames.getSheets()[0]);
    var row1        = masterSheet.getRange(1, 1, masterSheet.getLastRow(), 1);
    var rowV        = row1.getValues();
    var firstArray  = masterSheet.getDataRange().getValues();
    var dataList    = [];
    for (var i = 1; i &lt; rowV.length; i++) {
      dataList.push(firstArray[i][0]);
      dataList.push(firstArray[i][1]);
      dataList.push(firstArray[i][2]);
      dataList.push(firstArray[i][3]);
  
    }
    for (var j = 0; j &lt; rowV.length - 1; j++) {
      namesSheet.getRange(2, j + 1, 1, 1).setValue(dataList[j]);
    }
  }
  </code></pre>
  
  <p>So as of now it only works on one row, starting from the second row (to allow for column headers). And I suppose when I want to grab rows conditionally based on cell data, I will use an 'if' statement for the condition inside the 'for' loop, but I want the data to copy to the next available row in both sheets. I suppose I'd use something like:
     ' getLastRow + 1 '
  or something like that. I need this code to be as efficient as possible because of the amount of data and its purpose. I am pretty new to programming so please explain in detail, and thanks again.</p>