A script to move rows from one sheet to another based on certain conditions. I run this trigger every 24 hours to get rid of past data and save it as a backup so my apps are always easier and quicker to load.
function moveRows() {
var ss = SpreadsheetApp.getActive();
var source = ss.getSheetByName('Sheet1');
var val = source.getDataRange().getValues();
var PDate = new Date(new Date().setHours(0,0,0,0))
for (var row = val.length - 1; row >= 0; --row) {
Logger.log("Check: "+ val[row][1]+'----'+ PDate)
if ((val[row][42] == 'Completed' || val[row][42] == 'Cancelled') && val[row][1] <= PDate && val[row][39] == 3) {
ss.getSheetByName('Closed')
.appendRow(val[row]);
source.deleteRow(parseInt(row) + 1);
}
}
}
Question about the āprettyā function. I get this error messageā¦
TypeError: Cannot read property āgetBandingsā of null
More than getting it to work Iād like to understand the problem. As far as I can tell this means I havenāt declared the variable I am trying to get the value from?
How are you calling the function?
It should be something like format_sheet('Sheet 1')
I actually use this within a wrapper function, something like this:
function on_sheet_change(event) {
var sheetname = event.source.getActiveSheet().getName();
format_sheet(sheetname);
}
Thatās a simple example, normally Iāll have a an if/then/else block that first checks the sheetname, and then only calls the format_sheet() function for selected sheets.
That was the long answer.
The short answer is that error probably indicates that you didnāt give it a sheet name
Sorry, just realised that I didnāt address this question directly.
Yes, thatās correct. sheet is null (I assume because of the above), and so when you try and do anything with it (getBandings()), that error is thrown.