How exactly do you use isBlank() in a google apps script function?
function pushGeo()
{
var ssA = SpreadsheetApp.openById('###')
var ss = ssA.getSheetByName('mySheet');
var lastRow = ss.getLastRow();
var data = ss.getRange('G2:G'+lastRow);
for(var row=2;row<=lastRow;row++)
{
ss.getRange('G'+row+':G'+row).isblank(); // not working
if(isblank(data),'0','G'+row); // not working
}
}
I want to check a column 'G' for blank cells. If the cell is blank, I want to set its value to '0'. Ultimately, I want to take the column 'G' that was just checked for empty cells and pare it to another column 'N'. If the row in column 'G' is NOT empty (now with value '0') then push the value of column 'G' into column 'N'. Wanted to change the empty cells to '0' so that I can "see" the code better, easier parison, etc.
How exactly do you use isBlank() in a google apps script function?
function pushGeo()
{
var ssA = SpreadsheetApp.openById('###')
var ss = ssA.getSheetByName('mySheet');
var lastRow = ss.getLastRow();
var data = ss.getRange('G2:G'+lastRow);
for(var row=2;row<=lastRow;row++)
{
ss.getRange('G'+row+':G'+row).isblank(); // not working
if(isblank(data),'0','G'+row); // not working
}
}
I want to check a column 'G' for blank cells. If the cell is blank, I want to set its value to '0'. Ultimately, I want to take the column 'G' that was just checked for empty cells and pare it to another column 'N'. If the row in column 'G' is NOT empty (now with value '0') then push the value of column 'G' into column 'N'. Wanted to change the empty cells to '0' so that I can "see" the code better, easier parison, etc.
Share Improve this question asked Sep 9, 2017 at 13:29 testing123testing123 8357 gold badges18 silver badges38 bronze badges 1-
The method is case sensitive. The correct spelling is
isBlank()
notisblank()
. See developers.google./apps-script/reference/spreadsheet/… – Wicket Commented Sep 9, 2017 at 16:56
1 Answer
Reset to default 4If you have a a lot of data on a sheet you might want to consider doing it this way it runs a lot faster because you get and set all data just one time.
function ifGIsBlankThenMakeItZero()
{
var ssA = SpreadsheetApp.getActive();//changed from openById() for my convenience
var ss = ssA.getActiveSheet();//change from getSheetByName() for my convenience
var lastRow = ss.getLastRow();
var range = ss.getRange(2,7,lastRow,1);//row 2 column 7 (G) lastRow 1 column
var data = range.getValues();//Gets all data
for(var i=0;i<data.length;i++)//this runs over entire selected range
{
if(!data[i][0])//If true then it's blank
{
data[i][0]=0;//notice this is data[i][0] because there is only one column in the range.
}
}
range.setValues(data);//Sets all data.
}