Need help with If statement

M

mcmilja

Hello,

I need help with a nested if statement. How would I build the statement
using the following logic: If cell B2 = 2, then add text "00" to the front
of what's in cell A2 (="00"&A2).

SDF Character Result
A2: 63 B2:2 C2:0063

Thanks!
Jaret
 
K

Kevin B

=IF(B2=2,"00"&A2,"")

I don't know what you want for the false statement so I put a "" value
 
M

mcmilja

Thanks Kevin! How would I throw in several ORs into the statement?

If cell B2 = 1, then add text "000" to A2 (="000"&A2)
If cell B2 = 2, then add text "00" to A2 (="00"&A2) OR
If cell B2 = 3, then add text "0" to A2 (="0"&A2) OR
If cell B2 = 4, then add nothing to A2 (=""&A2) OR

SDF Characters Result
A2:9 B2:1 C2:0009
A2:63 B2:2 C2:0063
A2:105 B2:3 C2:0105
A2:1005 B2:4 C2:1005
 
K

Kevin B

The following formula pads your values based upon their respective lengths.
If the length of the value is equal to or greater than 4 you get the value,
otherwise the CHOOSE function pads zeroes based upon lenghts 1, 2 and 3:

=IF(LEN(A1)>=4,A1,CHOOSE(LEN(A1),"000"&A1,"00"&A1,"0"&A1))
 

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