简体   繁体   English

Excel的左和右公式错误地拆分单元格

[英]Excel LEFT and RIGHT Formulas Incorrectly Splitting Cells

I am trying to do something very basic--take a list of emails and web urls in one column, and split them into a column for emails, and the other for the urls. 我正在尝试做一些非常基本的事情-将电子邮件和Web网址的列表放在一个列中,然后将它们拆分为一个列,以容纳电子邮件,另一列则包含URL。

To accomplish this, I have tried the following formulas: 为此,我尝试了以下公式:

=LEFT(A2, SEARCH(" ",A2,1))

And

=RIGHT(A2, SEARCH("  ",A2,1))

Should the format of the first column be [Email] [URL] it SHOULD split this so the the column with the first function receives the emails, whereas the second would receive the URL's. 如果第一列的格式为[Email] [URL],则应将其拆分,以便具有第一个功能的列接收电子邮件,而第二个功能的列将接收URL。

However, this is not the case. 然而,这种情况并非如此。 Instead, I get something ugly, like this: 相反,我得到了一些丑陋的东西,像这样: 在此处输入图片说明

As you can see, in the first cell, it works perfectly fine. 如您所见,在第一个单元格中,它工作得很好。 However, in the lower cells you can clearly see things break. 但是,在较低的单元格中,您可以清楚地看到事物破裂。 Values overlap, like in row 6 column 3... why? 值重叠,例如第6行第3列...为什么? There are clearly no additional spaces besides those between the email and url in the first column. 显然,第一列中的电子邮件和URL之间没有空格。

SEARCH(" ",A2,1) finds the first space location from the LEFT . SEARCH(" ",A2,1)LEFT中找到第一个空间位置。

So it is passing that number to the RIGHT() Function which expects the number of characters wanted from the RIGHT not the LEFT . 因此它将这个数字传递给RIGHT()函数,该函数期望从RIGHT而不是LEFT需要的字符数。

Use: 采用:

=RIGHT(A2, LEN(A2) - SEARCH("  ",A2,1))

The search returns the length of the email, so in your formula you are taking the right-most quantity equal to the length of the email and not the website. 搜索将返回电子邮件的长度,因此在您的公式中,您要获取的最右边的数量等于电子邮件的长度,而不是网站的长度。 You need to use: 您需要使用:

=RIGHT(A2,LEN(A2)-SEARCH(" ",A2,1))

如果您不想在每一行使用http:// ,这就是您的陈述, 如您所见,在第一个单元格中,它运行得很好 ,您可以使用

=RIGHT(A2,LEN(A2)-SEARCH("/",A2,1)-1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM