Use an if statement in Javascript to determine if a cell in a google spreadsheet has contents -


this code gets values different locations in sheet , writes combined data sheet.

problem is, if row blank, code copies blank row receiving sheet. first check cell "b8", , if blank, skip function , run next function.

if cell "b8" has data in (anything, date), run function copy code new sheet.

here code:

function submitbuttonclick() {      //begining of entry8 transfer start.        var ss = spreadsheetapp.getactive();    var sheet = ss.getactivesheet();    logger.log('sheet.getname(): ' + sheet.getname());        if (sheet.getname() !== "timecardentry") {return;};        var targetsheet = ss.getsheetbyname("timesheetrecord");    var arrayofdata = [];        var weekbegining = sheet.getrange(4, 11).getvalue();    var employname = sheet.getrange(4, 4).getvalue();        var entry8 = sheet.getrange(8,2,1,9);    var entry8data = entry8.getvalues()[0];//get inner array of rows data    logger.log('entry8data: ' + entry8data);      //add weekbegining , employname values array    entry8data.splice(0, 0, weekbegining, employname);    //push row data another, outer array. setvaluies() needs 2d array.    arrayofdata.push(entry8data);        logger.log(arrayofdata);        var lastrow = targetsheet.getlastrow();    logger.log('lastrow: ' + lastrow);                                            targetsheet.getrange(lastrow+1, 1, 1, entry8data.length).setvalues(arrayofdata);        sheet.getrange('b8:m8').clearcontent();        //end of entry8 transfer.    }

you add code in between these line:

var arrayofdata = [];  var weekbegining = sheet.getrange(4, 11).getvalue(); 

change to:

var arrayofdata = [];  var b8_value = sheet.getrange(8, 2).getvalue(); if (b8_value === "") {return;};//if cell value empty stop code here  var weekbegining = sheet.getrange(4, 11).getvalue(); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -