嵌套的IF用零填充数字 [英] Nested IFs to pad numbers with zeroes

查看:183
本文介绍了嵌套的IF用零填充数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用零填充列,以便以后可以连接它的值。它需要4个字符,所以我试图使用嵌套的If语句。

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)

我只得到'#Value'。我哪里错了?

I only get '#Value'. Where am I going wrong?

推荐答案

不要重新发明轮子:已经有一个内置功能。

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

=TEXT(G2,"0000")

现在,要具体回答您的问题,您收到错误的原因是您的 IF 函数由于错误放置右括号而没有正确嵌套

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 ).

是:

=IF(LEN(G2)=3,"0" & G2),IF(LEN(G2)=2,"00" & G2,G2)
                      ^

应该是:

=IF(LEN(G2)=3,"0" & G2,IF(LEN(G2)=2,"00" & G2,G2))
                                                 ^

但是,这不会给你预期的结果。只需使用内置的 TEXT 函数。

Still, this won't give you the expected results. Just go with the built-in TEXT function.

这篇关于嵌套的IF用零填充数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆