Google Script for Spreadsheets - error: Argument must be a range -
i new google scripting , running can't figure out. trying name range hope of putting array , populating sheet data.
i running problems naming range. want able iterate through , name many ranges, i'd able use variables row numbers.
if try this:
var rngproject = "a8:y21"; var rngname = "project1";
then works , have data in array. but, mentioned, want use variables row numbers, range name, shown below.
if try this:
var rngproject = "a" + strtrow + ":y" + totrows + strtrow - 1; var rngname = "project" + tostring(i);
on line:
var rng_to_name = active_spreadsheet.getsheetbyname(sheet_name).getrange(address);
i getting error: "argument must range." in debugger address value shows nan, think not right. i've tried using strrange (commented out below) , same error on same line.
is there way can take value , cast range type, or there else doing wrong?
function nameprjrange () { var = 1 var strtrow = 8; var shtname = "user input week: test"; var totrows = 14; //var strrange = "a" + tostring(strtrow) + ":y" + tostring(totrows + strtrow - 1); var rngproject = "a" + strtrow + ":y" + totrows + strtrow - 1; var rngname = "project" + tostring(i); //logger.log(strrange); logger.log(rngproject); logger.log(rngname); namerange(shtname, rngproject, rngname); } // given sheet name (assumed in active spreadsheet, address using "a1" notation, // , name string, assign name range address in given sheet. function namerange(sheet_name, address, rng_name) { // create spreadsheet object. logger.log("entered namerange function") var active_spreadsheet = spreadsheetapp.getactivespreadsheet(); // range object firstly getting sheet object spreadsheet object , pass // "address" argument sheet "getrange()" method. var rng_to_name = active_spreadsheet.getsheetbyname(sheet_name).getrange(address); // use spreadsheet object method "setnamedrange()" assign range name range object. logger.log("about set named range"); logger.log(rng_name); logger.log(rng_to_name); active_spreadsheet.setnamedrange(rng_name, rng_to_name); }
use:
var rngproject = "a" + strtrow + ":y" + (totrows + strtrow - 1);
as performing string concatenation here, parser attempting concatenate (ie not adding totrows strtrow), , drop it's bundle when arrives @ minus sign, isn't valid string operator. need put parentheses around arithmetic part.
https://developer.mozilla.org/en-us/docs/javascript/guide/expressions_and_operators#string_operators
Comments
Post a Comment