Using of a simple If then statement

Rolf Beck 20 Reputation points


I am new to office script and would like to program a simple condition:

If the cell C6 contains the value 1, the value 2 should be inserted. If the cell C6 contains the value 2, the value 1 should be inserted. So every time the script is executed, the value of C6 changes between 1 and 2.

I have tried it this way, but the value does not change as desired. It seems that the "else" statement is not executed:

let myvalue = "C6";
	if (myvalue = "1") {
	} else {
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
689 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michelle Ran 256 Reputation points Microsoft Employee

    Hi @Rolf Beck - when comparing values, you should use either the double or triple equals sign rather than the singular. See

    Hopefully that helps!

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful