Excel 公式包含错误

发布于 2024-10-01 11:41:35 字数 665 浏览 3 评论 0原文

我在这个Excel公式中有一个错误,我无法弄清楚:

=LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))&", "&SUBSTITUTE(RIGHT(B3,LEN(B3)-FIND("&",B3&"&")-1),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))),""))

它可能看起来像一个大公式,但它的目的是如果单元格中没有&符号,则返回一个空单元格,如果没有逗号但是& 符号存在,则返回该符号,例如:

KNUD J & MARIA L HOSTRUP

为:

HOSTRUP,MARIA L

否则,没有 & 符号,但有一个逗号,所以我们只返回:LEFT(A1,FIND("&",A1,1)-1)。

看起来很基本,但公式一直给我错误消息并且没有指出问题。

I have an error in this excel formula and I can't just figure it out:

=LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))&", "&SUBSTITUTE(RIGHT(B3,LEN(B3)-FIND("&",B3&"&")-1),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))),""))

It may seem like a big formula, but all it's intended to do is if no ampersand is in a cell, return an empty cell, if no comma but ampersand exists, then return this, for example:

KNUD J & MARIA L HOSTRUP

into this:

HOSTRUP,MARIA L

Otherwise, there is no ampersand but there is a comma so we just return: LEFT(A1,FIND("&",A1,1)-1).

Seems basic, but formula has been giving me error message and doesn't point to the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾铮苏瑾 2024-10-08 11:41:35

你的错误在这里:

=LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),

此时,逗号不适用于任何东西,因为正确的运算符具有匹配的括号

至于你想要什么?让我们将其分解为您实际要求的内容:

如果单元格中没有&符号,则返回空单元格,

B4=Find("&", B3&"&")
B5=IF(B4>LEN(B3),"",B6)

如果没有逗号但存在&符号

B6=IF(FIND(",", B3&",")>LEN(B3),B8,B7)

则将其转过来,例如:

克努德 J &玛丽亚·霍斯特鲁普
进入这个:
玛丽亚·霍斯特鲁普

我猜你是想写最后一个完整的词?让我们标记最后一个完整的单词:

B9=SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))
B10=RIGHT(B7,LEN(B9)-FIND("@",B9))

以及&符号和最后一个单词之间的东西

B11=TRIM(MID(B9,B4 + 1, LEN(B9)-FIND("@",B9)-1))

然后计算它很容易

B7=B10&","&B11

否则,没有 & 符号但有逗号,所以我们只返回:
LEFT(A1,FIND("&",A1,1)-1)。

好吧,如果你想要的话,让我们把它放在 B8 中

B8=LEFT(A1,FIND("&",A1,1)-1)

(但我认为你实际上是指 B3 而不是 A1),

B8=LEFT(B3,FIND("&",B3,1)-1)

这样你就得到了它(B5 包含你正在寻找的信息)它需要几个单元格,但它更容易以这种方式进行调试。如果您想折叠它,也可以(但这样做需要更多代码,因为我们可以通过多次引用先前计算的单元格来减少重复)。

摘要:

B3=<Some Name with & or ,>
B4=FIND("&", B3&"&")
B5=IF(B4>LEN(B3),"",B6)
B6=IF(FIND(",", B3&",")>LEN(B3),B7,B8)
B7=B10&","&B11
B8=LEFT(B3,FIND("&",B3,1)-1)
B9=SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))
B10=RIGHT(B9,LEN(B9)-FIND("@",B9))
B11=TRIM(MID(B9,B4 + 1, LEN(B9)-FIND("@",B9)-1))

当我输入“KNUD J & MARIA L HOSTRUP”时,我在 B5 中得到“HOSTRUP,MARIA”。

Your error is here:

=LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),

At this point, the comma doesn't apply to anthing, because the right operator has matching parens

As far as what you want? Let's break that up into what you actually asked for:

if no ampersand in a cell, return empty cell,

B4=Find("&", B3&"&")
B5=IF(B4>LEN(B3),"",B6)

if no comma but ampersand exists

B6=IF(FIND(",", B3&",")>LEN(B3),B8,B7)

then turn this, for example:

KNUD J & MARIA L HOSTRUP
into this:
HOSTRUP,MARIA L

I'm presuming you mean to put the last whole word? Let's mark the last whole word:

B9=SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))
B10=RIGHT(B7,LEN(B9)-FIND("@",B9))

And the stuff between the ampersand and the last word

B11=TRIM(MID(B9,B4 + 1, LEN(B9)-FIND("@",B9)-1))

Then calculating it is easy

B7=B10&","&B11

Otherwise, there is no ampersand but there is a comma so we just return:
LEFT(A1,FIND("&",A1,1)-1).

Well, if you want that, let's just put that in B8

B8=LEFT(A1,FIND("&",A1,1)-1)

(But I think you actually mean B3 instead of A1)

B8=LEFT(B3,FIND("&",B3,1)-1)

And there you have it (B5 contains the information you're looking for) It took a few cells, but it's easier to debug this way. If you want to collapse it, you can (but doing so is more code, because we can reduce duplication by referencing a previously calculated cell on more than one occasion).

Summary:

B3=<Some Name with & or ,>
B4=FIND("&", B3&"&")
B5=IF(B4>LEN(B3),"",B6)
B6=IF(FIND(",", B3&",")>LEN(B3),B7,B8)
B7=B10&","&B11
B8=LEFT(B3,FIND("&",B3,1)-1)
B9=SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))
B10=RIGHT(B9,LEN(B9)-FIND("@",B9))
B11=TRIM(MID(B9,B4 + 1, LEN(B9)-FIND("@",B9)-1))

When I put in "KNUD J & MARIA L HOSTRUP", I get "HOSTRUP,MARIA" in B5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文