答案1
我想使用新LET
功能:
=LET(x,TRIM(RIGHT(SUBSTITUTE(D2,",",REPT(" ",99)),99)),y,SUBSTITUTE(x," ",""),IF(AND(ISNUMBER(-y),OR(LEN(y)=10,LEN(y)=12)),SUBSTITUTE(D2,", " & x,""),D2))
算法
x
返回最后一个以逗号分隔的子字符串y
返回x
时删除了空格。- 检查是否
y
为数字,并且长度为10
或12
- 如果通过检查,则在主字符串中替换
x
前面的,
- 如果不是,则仅返回原始字符串。
*如果您没有该LET
功能,您可以尝试:
=IF(AND(ISNUMBER(-SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(D2,",",REPT(" ",99)),99))," ","")),OR(LEN(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(D2,",",REPT(" ",99)),99))," ",""))=10,LEN(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(D2,",",REPT(" ",99)),99))," ",""))=12)),SUBSTITUTE(D2,", " & TRIM(RIGHT(SUBSTITUTE(D2,",",REPT(" ",99)),99)),""),D2)
笔记 根据评论改变电话号码的定义
如果不是电话号码10或者12数字,它们是10-12数字,那么您需要做的就是更改公式中的长度检查。
换句话说,
...OR(LEN(y)=10,LEN(y)=12)...
你用:
OR(LEN(y)>=10,LEN(y)<=12)
因此,这会将公式更改为:
=LET(x,TRIM(RIGHT(SUBSTITUTE(D3,",",REPT(" ",99)),99)),y,SUBSTITUTE(x," ",""),IF(AND(ISNUMBER(-y),OR(LEN(y)>=10,LEN(y)<=12)),SUBSTITUTE(D3,", " & x,""),D3))
如果您正在使用更长的公式,则可以在更长的公式中进行类似的更改。