Home Ask Login Register

Developers Planet

Your answer is one click away!

PizzaAndCode February 2016

Msgbox if YES or NO

This should be super easy! The code merely consists of a message box with a Yes or No choice. Given that choice, a corresponding string is written into cell A1. I see no problem with it compared to google's script examples. What am I missing?

function msgbox() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();

var answer = Browser.msgBox("Confirm", "Does this work?", Browser.Buttons.YES_NO);

//if user clicks yes
if(answer === Browser.Buttons.YES) {
    //then enter YES into cell A1
    s.getRange("A1").setValue() === "YES";
    } else {
    //else enter NO into cell A1
    s.getRange("A1").setValue() === "NO";


phenxd February 2016

I have never used Google App Scripts, but based on my other programming experiences, I feel like

s.getRange("A1").setValue() === "YES";

might be the problem. Usually, the '===' operator is used to compare 2 values.

'aaa' === 'aaa' --> return true

In your case, don't you want to set a value?


is what I would feel appropriate.

Serge insas February 2016

You are simply using setValue() the wrong way. Refer to the documentation here. It should simply be s.getRange("A1").setValue('YES')

Post Status

Asked in February 2016
Viewed 1,017 times
Voted 12
Answered 2 times


Leave an answer

Quote of the day: live life