Reputation: 2253
I'm trying to create a custom function in my google spreadsheet with the script editor.
I can't seem to allow the user to give the function an array as the argument.
My script works when I hardcode like this:
var values = SpreadsheetApp.getActiveSheet().getRange("G2:j30").getValues();
What I want to do is pass the array as an argument:
function arrayToList(chosenArray) {
...
var values = SpreadsheetApp.getActiveSheet().getRange(chosenArray).getValues();
...
}
Upvotes: 4
Views: 7226
Reputation: 38160
There are two ways to pass an array as argument to a Google Sheets custom function
A1:D5
. Usage: =myCustomFunction(A1:D5)
.{1,2;"Yellow","Orange"}
. Usage: =myCustomFunction({1,2;"Yellow","Orange"})
.
Note: If your spreadsheet is set to use comma as decimal separator use /
as column separatorReferences
Upvotes: 3
Reputation: 5645
Riku - Did you try calling your function as arrayToList(G2:j30)? I believe Apps Script will convert that selected range to a comma separated string (going left -> right and then top->down).
It wont be the same as a the Range object, but at least you can get a CSV string representation of the selected range and perhaps that is sufficient?
Upvotes: 1
Reputation: 8660
Now this functionality is not implemented in GAS. There are similar questions in SO (here and here). You can post a feature request to the issue tracker.
Upvotes: 2