Reputation: 29
I would like to create a function in script editor that would allow me to input data from a cell on another sheet without having to put 'sheet1!A1' in the formula.
Say I have my sheet name in A1 and want to return the number in the first row and first col (i.e. A1) of that sheet. I would like to show that value with a formula as simple as getcell(A1,1,1)
Here's what I've got but I get an error saying "Exception: Range not found (Line 4)"
function getcell(sheetName,row, col) {
var ss = SpreadsheetApp.getActive()
var range = ss.getSheetByName(sheetName).getRange(row, col)
ss.getRange(range).getValue();
}
Upvotes: 0
Views: 60
Reputation: 26796
You need to pass the sheet name in quotes
You are trying to get the range twice
For a custom funciton, you need to return the value
Sample code:
function getcell(sheetName,row, col) {
var ss = SpreadsheetApp.getActive()
var range = ss.getSheetByName(sheetName).getRange(row, col)
return range.getValue();
}
Sample call:
=getcell("Sheet1",1,1)
Upvotes: 2
Reputation: 201378
I believe your goal is as follows.
A1
as A1Notation by putting =getcell(A1,1,1)
to a cell.In this case, how about the following modification?
function getcell(sheetName, row, col) {
var ss = SpreadsheetApp.getActive()
var range = ss.getSheetByName(sheetName).getRange(row, col);
var res = range.getA1Notation();
return res;
}
range
is used in getRange(range)
. By this, such an error occurs.getA1Notation()
is used.getA1Notation()
to getValue()
.Upvotes: 2