[英]Excel: reformat/replace part of string in cell
I have an Excel file that contains descriptions: 我有一个包含说明的Excel文件:
Trees [1]
Buildings[20]
Cameras[303]
What I'm wanting to do is format what's inside the brackets to contain 4 digits. 我想做的是将方括号内的内容格式化为4位数字。 I know the custom format is "0000", but can I apply that format to those numbers?
我知道自定义格式为“ 0000”,但是我可以将该格式应用于这些数字吗?
The end result would look like: 最终结果如下所示:
Trees [0001]
Buildings[0020]
Cameras[0303]
Thank you for any tips! 谢谢您的提示!
假设Trees [1]位于A1单元上,然后尝试以下公式:
=LEFT(A1,FIND("[",A1))&RIGHT("0000"&MID(A1,FIND("[",A1)+1,LEN(A1)-FIND("[",A1)-1),4)&"]"
I'm going to assume that your number is always in []
, and those only occur once per string. 我将假设您的数字始终在
[]
,并且每个字符串仅出现一次。
Using LEFT
and MID
to slice the string up, and then formatting the number, I end up with a formula that looks like this: 使用
LEFT
和MID
将字符串切成薄片,然后格式化数字,最后得到一个看起来像这样的公式:
=LEFT(A1,FIND("[",A1)) & TEXT(VALUE(MID(A1,FIND("[",A1)+1,FIND("]",A1)-FIND("[",A1)-1)),"0000") & "]"
Broken down: 细分:
=LEFT(A1,FIND("[",A1))
<< grab all the letters up to the [ =LEFT(A1,FIND("[",A1))
<<抓取所有直到[
&
then add in: &
然后加入:
TEXT(VALUE(MID(A1,FIND("[",A1)+1,FIND("]",A1)-FIND("[",A1)-1)),"0000")
<< the number ( VALUE ) found between the brackets ( FIND ), and then format that number ( TEXT ) to be the format you desire TEXT(VALUE(MID(A1,FIND("[",A1)+1,FIND("]",A1)-FIND("[",A1)-1)),"0000")
<<数字(在括号( FIND )之间找到VALUE ),然后将该数字( TEXT )格式化为所需的格式
&
then add in: &
然后加入:
"]"
<< the final close bracket "]"
<<最后的右括号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.