Appending separators in the formula

删除回忆录丶 提交于 2021-02-11 13:30:19

问题


Can someone help on this? I have column A with telephone number and Column B with country code. I want to remove the country code in column A if it is there to avoid duplication. Can someone help me?

Column A 1234567 Column B 1 Column C 1234567

Column C should have the formula to check if 1 is already in the beginning of the cell value A, if yes, it'll remove it, but if not, column B value will be added to it. Another scenario is below: Column A 234567 Column B 1 Column C 1234567

Also, I would like to add separators in this formula after the country code, and after three digits of the country code based on column 1 with removed country code in it.

How to append it in this formula?

=IF(B1 = --LEFT(A1, LEN(B1)),A1,--(B1&A1))

Appreciate your answer!


回答1:


As far as I understand what you describe, you may be after something like this:

="+"&TEXT(B1,"0")&"-"&
IF(LEFT(TEXT(A1,"0"),LEN(TEXT(B1,"0")))=TEXT(B1,"0"),
   MID(TEXT(A1,"0"),LEN(TEXT(B1,"0"))+1,99),
   A1)

The statement about "after three digits of the country code based on column 1 " is unclear. This formula gives you tools to add characters before and after the country code, while it removes country code duplication.

edit after comments You don't really describe it, at least not clearly, but it looks like you want a vertical bar after the country code and again after the first three digits of the phone number. The formula to achieve that is

=TEXT(B1,"0")&"|"&
REPLACE(IF(LEFT(TEXT(A1,"0"),LEN(TEXT(B1,"0")))=TEXT(B1,"0"),
   MID(TEXT(A1,"0"),LEN(TEXT(B1,"0"))+1,99),
   A1),4,1,"|")

another edit after stitching together what else you might want but don't clearly describe: If column B can possibly contain either numbers like 1 or 63 but also text that starts with a country code, followed by a space and some other stuff, like 63 2, then you can use this formula

=LEFT(TEXT(B2,"0"),FIND(" ",TEXT(B2,"0")&" ")-1)&"|"&
REPLACE(IF(LEFT(TEXT(A2,"0"),LEN(TEXT(B2,"0")))=TEXT(B2,"0"),
   MID(TEXT(A2,"0"),LEN(TEXT(B2,"0"))+1,99),
   A2),4,1,"|")



来源:https://stackoverflow.com/questions/64600639/appending-separators-in-the-formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!