1

I am converting VBA script to google script. I am 99% completed. This is problem one of two. I am embarrassed it's so simple yet my VBA head cannot seem to get it right in google script.

My VBA is this this

If Range("A3") <> "BOOKED" Then
xxxxxx(lots of code)

End If

I want the code to not run if cell "A3" = "BOOKED".

function ClearDataMacro() {
    var spreadsheet = SpreadsheetApp.getActive();
    /// end if range (A3:E5)= "BOOKED"
    var READY = ""
    var READY = spreadsheet.getRange('A3:E5').getValues();
    if (READY = "BOOKED") {
        spreadsheet.getRange('Y1:Z1').activate();
        spreadsheet.getCurrentCell().setValue("OPTION ONE");
    }
    spreadsheet.getRange('Y2:Z2').activate();
    spreadsheet.getCurrentCell().setValue("OPTION TWO") {
        spreadsheet.getRange('Y3:Z3').activate();
        spreadsheet.getCurrentCell().setValue("OPTION THREE");
    }
    spreadsheet.getRange('Y4:Z4').activate();
    spreadsheet.getCurrentCell().setValue("OPTION FOUR");
}

No matter what boolenan expression I use (<>,=,!=,>,<), the script completely ignores my if statement and runs the script for all the OPTIONS. I get four answers.

Mig82
  • 3,665
  • 1
  • 30
  • 55
T W
  • 9
  • 2
  • 1
    Welcome to [so]. Please read https://developers.google.com/apps-script/guides/sheets then if you still need help add a brief description of your search/research efforts as is suggested in [ask]. – Rubén Jun 07 '20 at 04:51
  • What have you tried? Show your current code and the issue with that code. See [mcve] – TheMaster Jun 07 '20 at 08:00
  • https://stackoverflow.com/questions/11871616/in-javascript-vs/ – TheMaster Jun 07 '20 at 11:45
  • 2
    Since the question is closed I'll tell you in a comment. Your `if` statement is wrong because you're using the _assignment_ (`=`) operator when you should be using the _equals_ (`==` or `===`) operator. Also, if the rest of your code should not be executed when that condition is met, wrap it in an `else` statement, like so `if(READY==="BOOKED"){...}else{...}`. You were missing a closing curly bracket, so I edited and indented your code for readability. I think this is what you meant anyway. Amend it again if not. – Mig82 Jul 15 '20 at 09:13

0 Answers0