ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Need help with If statement (https://www.excelbanter.com/excel-discussion-misc-queries/191430-need-help-if-statement.html)

mcmilja

Need help with If statement
 
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

Kevin B

Need help with If statement
 
=IF(B2=2,"00"&A2,"")

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


"mcmilja" wrote:

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


mcmilja

Need help with If statement
 
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

"Kevin B" wrote:

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

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


"mcmilja" wrote:

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


Kevin B

Need help with If statement
 
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))
--
Kevin Backmann


"mcmilja" wrote:

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

"Kevin B" wrote:

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

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


"mcmilja" wrote:

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



All times are GMT +1. The time now is 04:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com