I'm attempting to split data in a sheet (MASTERS) by the data in column E. The data is a number. I have the destination sheets set up in the same workbook which are named correctly, (eg. 3, 4, 5 etc) but every time I run I am getting the error
TypeError: Cannot call method "getRange" of null. (line 12, file "02. split by column E"
var ss=SpreadsheetApp.getActiveSpreadsheet();
var master = ss.getSheetByName('MASTER');
var colWidth = master.getMaxColumns();
function copyRowsOnCondition() {
var data = master.getDataRange().getValues();
for(n=0;n<data.length;++n){
if(data[n][4].length<16){
Logger.log(data[n][4])
var dest = ss.getSheetByName(data[n][4].toString().replace(/ /g,''));
var destRange = dest.getRange(dest.getLastRow()+1,1);
master.getRange(n+1,1,1,colWidth).copyTo(destRange);
}
}// loop
}
dest
sheet name? You are loggingdata[n][4]
but setting thedest
asdata[n][4].toString().replace(/ /g,'')
so you may be seeing a value in the log that is different than the value you are actually trying to get which would cause an error. The error is saying that your sheet by that name does not exist – random-parts12
? and double check that there is a sheet namedMASTER
. the error has to do with there not being a sheet object to callgetRange
on – random-parts