Answer the question
In order to leave comments, you need to log in
How to check for an empty cell in Google Sheets?
I have a loop that goes through the cells and I need it to stop when this cell is simple, the getLastRow and getLastColumn methods will not work.
The column lists names. I need a condition for stopping this loop so that it does not execute a static number of times, but how many rows I have filled.
The code is something like this:
var ss = SpreadsheetApp.getActiveSpreadsheet()
var as = ss.getActiveSheet()
for(var i = 0; i< 1000; i++){
var name = as.getRange(2+i, 1).getValue()
}
Answer the question
In order to leave comments, you need to log in
do {
// тело цикла
let name = as.getRange(2+i, 1).getValue()
} while (name!="");
Try something like this:
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sss = ss.getActiveSheet();
const sss_max_rows = ss.getMaxRows();
const sss_frozen_rows = 2; // ss.getFrozenRows() + 1;
const sss_values = sss.getRange(sss_frozen_rows, 1, sss_max_rows-sss_frozen_rows, 1);
sss_values.some(function (item, i) {
let name = item[0];
// Остановить цикл как только встретим пустую ячейку
if ( name == "" ) return true;
// Тут ваш код ...
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question