I'm trying to make a script for my Google spreadsheet.
What I want is for the script to check if a cell is empty in one sheet, and if its not, I want it to transfer that data into the cell of another sheet. Whenever I try this, it keeps saying "Cannot call method "getRange()" of undefined."
This is all I got so far:
function timesheets(){
var ss = SpreadsheetApp.openById("1iL2Didv_YOLpTad5WdR3kZSjLOLTSQk_yV-gQhh4RXs");
if("ss!C2" != ""){
var Tasks = ss.getRange("C2").getValue();
}
}
I'm trying to create a new function instead of using the functions on Google sheets. Would I have to include the names of both the spreadsheets?
You are accessing a spreadsheet, you need to get down to the sheet level first.
I suggest getting the script to work within the same spreadsheet before you try to talk from one to another.
The spreadsheet that has the code in it (target) needs to know the Id of the sheet that it is looking at for data (source). When you want to write the value to the (target) spreadsheet, you need to give it a variable to write to;
SECTION UNDERNEATH IS POST-EDIT ##
I created two spreadsheets.
In one called "target" I placed the following code
I replaced "*****************" with the Id from source.
Within the script editor I ran the function timesheets()
The value "hello" appeared in the target cell C2
In the script editor I went to
View>Execution transcripts
This produced the following