Reputation: 4099
Consider the following (partial) Excel sheet:
| A | B C D
-+---+------------------
1|id | comp1 comp2 comp3
-+---+------------------
2| 1 | 1 0 0
3| 1 | 1 0 0
4| 2 | 0 1 0
5| 3 | 0 0 1
6| 1 | 1 0 0
7| 3 | 0 0 1
As an example, if filled in all zero's and one's in columns B
, C
and D
by hand. I need to automate this because my dataset is to large to do it all manually. I need, for instance for cell B2
, a formula which checks whether value of A2
is similar to company id
in cell B1
. If so, set a 1
, else a 0
. Another example: take row 4. It has company id
2
in cell A4
so B4
(comp1) should be 0
, C4
1
and D4
0
.
I have used the following formula in cell B2, ready to be dragged to all other cells:
=IF($A2=RIGHT(B$1;1);1;0)
However, it puts a 0
in B2. I don't understand, because A2
has value 1, and so does RIGHT(B1;1)
, so IF(1=1;1;0)
, so B2
should get value 1
. But it doesn't where am I going wrong?
Upvotes: 0
Views: 166
Reputation: 211
Because right() returns a string and you compare a string to a number. You need to transform that string to a number, e.g. with value(right(...)).
Upvotes: 5