bex77: (Default)
bex77 ([personal profile] bex77) wrote2007-07-18 02:55 pm

An Excel formula?

Do you know Excel? I need help!

I need an Excel formula. I can make it work on paper, but Excel won't take it. It may be something simple, like a missing comma or paren, or I might be totally off. I used to be an ace, but my Excel foo has been rusting for awhile.

Here's the scoop.

I have two columns of data (A and B).

If they are the same, I want C to zero.
If A is higher, I want a 1.
If B is higher, I want a 2.

What formula do I put in C?

A B C
4 2 1
4 4 0
4 6 2

Here is what I tried:
=IF(A-B=0,0,=IF(A>B,1,2))
OR
=IF(A-B=0,0,(=IF(A>B,1,2)))

Excel doesn't like either one. I even tried the "function entering" wizard, to no avail.

Then I tried making two columns, trying to get the two clauses then compare them in a third. Didn't get very far on that front.

If anyone has a clue, I'd appreciate it.

Thanks!

[identity profile] wellstar.livejournal.com 2007-07-18 07:41 pm (UTC)(link)
In column C1, type:

=IF(A1>B1,1)+IF(A1=B1,0)+IF(A1<B1,2) You can then drag-extend it down so it applies to the rest of the C column: the A1 & B1 would turn into A2 & B2 in the formula in C2, A3 & B3 in C3, etc.

[identity profile] trowa-barton.livejournal.com 2007-07-18 07:45 pm (UTC)(link)
What she said with regards to drag-extending the formula. However, there is no "+" for the second and third IF statements, hence:

=IF(A1-B1=0,0,IF(A1>B1,1,2))

[identity profile] wellstar.livejournal.com 2007-07-18 07:47 pm (UTC)(link)
It does work with the "+" sign, but yeah, that's more elegant. I forgot about the true-false double-comma.

[identity profile] wellstar.livejournal.com 2007-07-18 07:45 pm (UTC)(link)
Okay, something weird is going on with the line break. The instructions to drag-extend it (I don't know the actual term...it's where you click the lower left corner of the cell and pull it down to the next row) should be on a separate line than the formula. Obviously, all you need to type in C1 is the equation with the three addends.