问题
I am looking to pad a columns with zero's so that I can later concatenate it's value. It needs to 4 characters, so I am trying to use a Nested If Statement.
=IF(LEN(G2)=3,"0" & G2),IF(LEN(G2)=2,"00" & G2,G2)
I only get '#Value'. Where am I going wrong?
回答1:
Don't reinvent the wheel: there is already a built-in function do to this.
=TEXT(G2,"0000")

Now, to answer your question specifically, the reason you got your error was that your IF
functions weren't properly nested due to misplaced right brackets )
.
Was:
=IF(LEN(G2)=3,"0" & G2),IF(LEN(G2)=2,"00" & G2,G2)
^
Should be:
=IF(LEN(G2)=3,"0" & G2,IF(LEN(G2)=2,"00" & G2,G2))
^
Still, this won't give you the expected results. Just go with the built-in TEXT
function.
回答2:
Don't need nested IF
's. Just concatenate 4 "0"s with your text, and then rip off the right 4 digits.
=RIGHT(CONCATENATE(REPT("0",4), G2),4)
来源:https://stackoverflow.com/questions/28943527/nested-ifs-to-pad-numbers-with-zeroes