Reputation: 1
I have a Google Spreadsheet containing 2 sheets.
If the content of a specific cell in sheet 1 is equal to something, I want to write something in a specific cell of the sheet 2.
As I need to do it a lot of times, I want to do it using Google App Script. Using VBA, this is super easy, but here it returns me that I "can't change or modify the properties of the object". Do you have any idea of what's wrong with my code?
Thank you for your help !
Here is my code :
function synthese() {
var results = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('results');
var synthese = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('synt');
B3 = results.getRange("B3");
if (B3="Yes") {
results.getRange("A1").setValue = "Yes";
} else {
results.getRange("A1").setValue = "No";
}
}
Upvotes: 0
Views: 254
Reputation: 10786
B3 is still a range, with properties such as size, background color, etc.
It is not a value, you can extract that via getValue()
.
Your second problem is that you are doing an assignment in the if.
Lastly setValue
is a method not an attribute, so the value needs to be supplied as an argument.
function synthese() {
var results = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('results');
var synthese = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('synt');
var B3 = results.getRange("B3"); // good practice to make variables local
if (B3.getValue() === "Yes") {
results.getRange("A1").setValue("Yes");
} else {
results.getRange("A1").setValue("No");
}
}
Upvotes: 1