Draketh
Draketh

Reputation: 11

Function to check for first blank cell

so, I'm attempting to define a custom function that returns the row number of the first blank cell it finds within a custom range.

function checkForBlank(startRow,startCol) {

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];
  var checkRow = startRow;
  var checkCol = startCol;
 var range = sheet.getRange(checkRow, checkCol);
 var i = checkRow;
  while (i < 100) {

    if(range.isBlank()) {

    return 5;


    } 
else { checkRow++; i++; }


}

}

The problem I'm having, is that whenever the first cell I'm checking isn't blank, the return value is blank. I can't figure out if there's an issue with my else statement or with using a loop. Any help would be much appreciated.

Upvotes: 0

Views: 97

Answers (1)

Sebastien
Sebastien

Reputation: 161

I am not sure of what is the format of your startRow and startCol variables, nor to understand what you are trying to do but I think you should update the variable range in the while loop, because isBlank tests if the whole range is blank or not : https://developers.google.com/apps-script/reference/spreadsheet/range#isBlank%28%29

Upvotes: 1

Related Questions