title: Searching and manipulating Excel data using JavaScript
body: <p>I have a HTML web form with 5 text inputs and a button calling a JavaScript function. The function as it stands, will open an existing Excel file, find the last populated row, insert a new row below it and put the form values in, one value to each cell. It then saves and exits.</p>
  
  <p>The spreadsheet however has many more than 5 columns, so the function only ever places the data into columns A - E.</p>
  
  <pre><code>function createData(){
  
      var first = document.getElementById('A').value;
      var second = document.getElementById('B').value;
      var third = document.getElementById('C').value;
      var fourth = document.getElementById('D').value;
      var fifth = document.getElementById('E').value;
  
      var xlDown = -4121
  
      var w =new ActiveXObject("Excel.Application");
      w.Visible=true;
  
      w.Workbooks.Open("file:\\Form.xls");
      objWorksheet = w.Worksheets(1);
  
      objRange = w.Range("A1");
      objRange.End(xlDown).Activate;
      intNewRow = w.ActiveCell.Row + 1;
  
      for (i=1; i&lt;10000; i++){
          objWorksheet.Cells(intNewRow, 1) = first;
          objWorksheet.Cells(intNewRow, 2) = second;
          objWorksheet.Cells(intNewRow, 3) = third;
          objWorksheet.Cells(intNewRow, 4) = fourth;
          objWorksheet.Cells(intNewRow, 5) = fifth;
      }
      w.ActiveWorkbook.SaveAs("file:\\Form.xls");
      w.Quit();
                alert("The data has been added to the spreadsheet");
  }
  </code></pre>
  
  <p>What I actually want to do is this:</p>
  
  <p>The spreadsheet may or may not already have data in columns A - G on each row.
  I want the function to search column B of the existing sheet for the text value of "first" (as defined above). If found, insert the other 4 values in corresponding cells in columns H-K. If not found then insert all 5 values into a new row "first" in Column B and the rest in column H-K.</p>
  
  <p>I've been messing with this for a long time and can't seem to crack it, though I know it can be done.</p>
  
  <p>Any help would be greatly appreciated!</p>