This function/trigger combo is intended to keep a log of live data on a daily basis. The intent is that N2:P2 get pasted as values at the bottom of Columns C:E.
pullvalue()
works fine if I run it manually. target_range
is breaking down when Clast
returns a zero value, but I can't figure out why. What am I missing? Thanks for your help/feedback!
function pullvalue() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var target = SpreadsheetApp.getActiveSpreadsheet(); var source_sheet = ss.getSheetByName("Production"); var target_sheet = target.getSheetByName("Production"); var source_range = source_sheet.getRange("N2:P2"); var Cvals = ss.getRange("C1:C").getValues(); var Clast = Cvals.filter(String).length; var target_range = target_sheet.getRange("C"+(Clast+1)+":E"+(Clast+1)) source_range.copyTo(target_range, {contentsOnly:true});}
Please verify this line:
var Cvals = ss.getRange("C1:C").getValues();
variable ss return currently activespreadsheet only, but when it runs from a time-driven trigger there is no active sheet, so you need to indicate the sheet, you can use getSheetByName() or getSheets() the line should look like this:
var sheet = ss.getSheetByName("Sheet1");
var Cvals = sheet.getRange("C1:C").getValues();
Hope this will help you.
Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.