if then

Copper Contributor

'=if b15 is "Roof" then c15 "1", OR if b15 is "Door c15 "2", OR if b15 is "Window" then c15 "4", 

cant get it to work ... ?

thanks in advance

1 Reply

@MrsRobinsonHeresToYou 

 

There are at least two ways to do it. 

Here, entered into cell C15, would be the easiest, but also the less robust, more problematic in the long run.

=IFS(B15="Roof",1,B15="Door",2,B15="Window",4)

 

Why is that more problematic in the long run, you ask: because you are "hard-coding the values" into the formula. But values like that often change over time, and hard-coded values are not "visible" ...

 

So a more reliable and more readily maintained approach is to put those kinds of variables into a table and use one of the many LOOKUP functions in a formula such as this

=VLOOKUP(B15,E13:F15,2,0)

referring to a table like this in the range E13:F15

mathetes_0-1677890262622.png

I'm attaching a spreadsheet with both examples working.