Simple Math Question

G

G

I want to reduce the code as much as possible with an IF/THEN statement,
here's what I want to do:

Take any number (always less than 120) and get the last digit (only). For
example, if I have 35, I want 5. Right now, I'm doing the following IF/THEN
statement:

C12 = 22 (I want 2)

=IF(C12>=30, C12 -30, IF(C12 >=20, C12-20, IF(C12>=10, C12-10, C12)))

I don't want to write all the code for 120 ... can anyone help me? Thanks.

G
 
G

Glenn

G said:
I want to reduce the code as much as possible with an IF/THEN statement,
here's what I want to do:

Take any number (always less than 120) and get the last digit (only). For
example, if I have 35, I want 5. Right now, I'm doing the following IF/THEN
statement:

C12 = 22 (I want 2)

=IF(C12>=30, C12 -30, IF(C12 >=20, C12-20, IF(C12>=10, C12-10, C12)))

I don't want to write all the code for 120 ... can anyone help me? Thanks.

G


=MOD(C12,10)
 
H

HARSHAWARDHAN. S .SHASTRI

=right(c12,1)


H S Shastri

=================================================
 
D

DILipandey

Hi G,

you can use following:-

=RIGHT(C12,1)
please let me know, if you still want to do it using if-then. thanks
--
Dilip Kumar Pandey
MBA, BCA, B.Com(Hons.)
(e-mail address removed)
(e-mail address removed)
New Delhi, India
 
H

HARSHAWARDHAN. S .SHASTRI

May be

=Right(c12,1)+a1*0+b1*0+c1*0+d1*0


===========================================================
 
B

Bernie Deitrick

G.

This may not be as simple as everyone thinks: it depends on the formatting of cell C12.

This will return the ones digit as displayed:
=MOD(ROUND(C12,0),10)

This will return the ones digit no matter how the number is displayed:
=INT(MOD(C12,10))

HTH,
Bernie
MS Excel MVP
 
M

Mike H

And what would be the point of that all you would end up with is the righmost
number/character in C12
 
D

David Biddulph

Perhaps he didn't realise that the +0 was there to convert the string to a
number?
But if he was trying to say that the formula was over-complicated, he could
have pointed out that the ,1 is superfluous.
 
M

Mike H

David,

I think the former and while I agree about the 1 I'll continue to put it
there to add clarity but perhaps next time I'll use *1 at the end and cause
total confusion.

Mike
 

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