title: How to fix 'getNextDataCell next skipped one cell' error in google script
body: <p>So here's this odd situation where I used this code and the selection was on A4 and after I use the getNextDataCell (NEXT) method it then selected C4 instead of B4????</p>
  
  <pre><code>Testsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.NEXT).setBackground('#000000').setFontColor('#ff0000');
  </code></pre>
  
  <p>And a photo after the execution: <a href="https://ibb.co/kBMf8Ff" rel="nofollow noreferrer">https://ibb.co/kBMf8Ff</a></p>
  
  <p>Here's my full code:</p>
  
  <pre><code>function Macro3() {
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    var Testsheet = spreadsheet.getSheetByName('Test');
    var data = Testsheet.getDataRange().getValues();
    for (var i = 0; i &lt; data.length; i++){
      if (data[i][0] == 'Harpeth Valley Utilities District'){
        var temp = i + 1;
        Testsheet.getRange('A'+temp).activate();
        Testsheet.getCurrentCell().setBackground('#000000').setFontColor('#ff0000');
        Testsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.NEXT).setBackground('#000000').setFontColor('#ff0000');
        Testsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).setBackground('#000000').setFontColor('#ff0000');
      }
    }
  };
  </code></pre>