"if" function ~ odd/even numbers

S

sokevin

i need to do this

if cell A1 is odd then i want to take the negative, if A1 is even the
i want the positive

=if(a1="odd", -a1, +a1)

how do i specify "odd"
 
F

Frank Kabel

Hi
you can try
=IF(MOD(A1,2),"odd","even")
or use the functions
ISEVEN and ISODD respectively. e.g.
=IF(ISODD(A1),"odd","even")

HTH
Frank
 
G

Gord Dibben

sokevin

=IF(ISODD(A1),(-A1),A1)

ISODD and ISEVEN are Analysis Toolpak functions.

Tools>Add-ins. Check ATP.

Gord Dibben Excel MVP
 
K

Ken Wright

Hmmm - Now I'm confused as to what he wanted :) I just read it as he wanted a
negative value regardless one way, and a positive value the other, but now I
read it your way as well - Too tired for this methinks (getting late over here)
:)
 
H

Harald Staff

=A1*(2*(MOD(A1,2)=0)-1)
The stuff inside the parentheses will return 1 if even, -1 if odd.
 
H

Harald Staff

Ken Wright said:
Hmmm - Now I'm confused as to what he wanted :) I just read it as he wanted a
negative value regardless one way, and a positive value the other, but now I
read it your way as well - Too tired for this methinks (getting late over here)

Sure is. Next logical step would be "which real life problem could possibly need a thing
like this?" and there goes a good night's sleep :)
 
G

Gord Dibben

All I looked at was OP's original attempt at a formula
=if(a1="odd", -a1, +a1)

and translated that to

=IF(ISODD(A1),(-A1),A1)

Straightforward to me<g>

Gord
 
H

Harald Staff

Gord Dibben said:
Harald
Even better. Don't need ATP.

Hi Gord

Thanks Gord. No, I never install ATP. I'm in Norway, and since the ATP functions don't
translate between language versions, and since my employer don't install it for my users
by default, it's a totally useless thing to me.

Best wishes Harald
Followup to newsgroup only please.
 
D

Dana DeLouis

Not sure, but another idea might be to switch the signs and drop the "=0"
part?

=A1*(-2*MOD(A1,2)+1)
=A1*(2*(MOD(A1,2)=0)-1)
--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


Harald Staff said:
The stuff inside the parentheses will return 1 if even, -1 if odd.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top