1

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?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188

2 Answers2

2

Don't reinvent the wheel: there is already a built-in function do to this.

=TEXT(G2,"0000")

enter image description here

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.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
1

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)
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Ditto
  • 3,256
  • 1
  • 14
  • 28