title: Google Sheets While Loop Until Empty Cell Found
body: <p>I'm trying to run the following script in Google Sheets but I can't get it to stop. Anyone able to advise where I'm going wrong.
  Thanks</p>
  
  <pre><code>function TriplicateEachLine() {
    var ss = SpreadsheetApp.getActive();
    var sheet = ss.getActiveSheet();
    var cc = ss.getCurrentCell();
    //Set New Hedders
    ss.getRange('R1').setValue('Stock');
    ss.getRange('S1').setValue('Weeks');
    ss.getRange('A2').activate();
    //Start of Loop Function
    while (cc &gt; ""){
      ss.getCurrentCell().offset(0, 17).setFormulaR1C1('=R[0]C[-5]-R[0]C[-4]');
      ss.getCurrentCell().offset(0, 18).setValue('12 Weeks');
      sheet.getRange(ss.getCurrentCell().getRow(), 1, 1, sheet.getMaxColumns()).activate();
      ss.getActiveSheet().insertRowsAfter(ss.getActiveRange().getLastRow(), 1);
      ss.getActiveRange().offset(ss.getActiveRange().getNumRows(), 0, 1, ss.getActiveRange().getNumColumns()).activate();
      sheet.getRange(ss.getCurrentCell().getRow() - 1, 1, 1, sheet.getMaxColumns()).copyTo(ss.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
      ss.getCurrentCell().offset(0, 17).setFormulaR1C1('=R[0]C[-5]-R[0]C[-4]');
      ss.getCurrentCell().offset(0, 18).setValue('8 Weeks');
      sheet.getRange(ss.getCurrentCell().getRow(), 1, 1, sheet.getMaxColumns()).activate();
      ss.getActiveSheet().insertRowsAfter(ss.getActiveRange().getLastRow(), 1);
      ss.getActiveRange().offset(ss.getActiveRange().getNumRows(), 0, 1, ss.getActiveRange().getNumColumns()).activate();
      sheet.getRange(ss.getCurrentCell().getRow() - 2, 1, 1, sheet.getMaxColumns()).copyTo(ss.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
      ss.getCurrentCell().offset(0, 17).setFormulaR1C1('=R[0]C[-5]-R[0]C[-4]');
      ss.getCurrentCell().offset(0, 18).setValue('4 Weeks');
      ss.getCurrentCell().offset(1, 0).activate();
    }
    Browser.msgBox("Complete!");
  };
  </code></pre>