简体   繁体   English

在Excel中第35位字符之前的最后一个空格中分割文本

[英]Split Text From the Last Space before the 35th position Character in Excel

eg Supplier Name - NANJING BANGSHING PRECISION MACHINERY TE 例如供应商名称-南京邦盛精密机械有限公司

I want to break this Name from the last space before the 35th position. 我想在第35个位置之前的最后一个空格处断开此名称。

In this Case 35th Position is - 'E' in MACHINERY, and I want to split it from the Space before it. 在这种情况下,第35位置是-在机械中为'E',我想将其与前面的空格分开。

ie

NANJING BANGSHING PRECISION - Cell A1
MACHINERY TE - Cell B2     

Currently I am finding the position of 2nd last space(For any Supplier Name going above 35 Characters, as the names are not longer than 70 chars), in order to complete my task. 目前,我正在寻找倒数第二个空格的位置(对于任何超过35个字符的供应商名称,因为名称不超过70个字符),以完成我的任务。 However, it's not a good practice. 但是,这不是一个好习惯。

=FIND("^"|SUBSTITUTE(A1|" "|"^"|LEN(A1)-LEN(SUBSTITUTE(A1|" "|""))-1))

to find the position 找到位置

NANJING BANGSHING PRECISION - Cell A1
MACHINERY TE - Cell B2

AGGREGATE can return the position of the last space before the 35th position. AGGREGATE可以返回第35个位置之前的最后一个空格的位置。 Use with REPLACE to remove unwanted characters. 与REPLACE一起使用以删除不需要的字符。

'first part
=REPLACE(A2, AGGREGATE(14, 7, ROW($1:$35)/(MID(A2, ROW($1:$35), 1)=" "), 1), LEN(A2), "")
'second part
=REPLACE(A2, 1, AGGREGATE(14, 7, ROW($1:$36)/(MID(A2, ROW($1:$36), 1)=" "), 1), "")

It was a little unclear on what to do if the 35th position was actually a space. 如果第35位实际上是一个空格,该如何做还不清楚。 The above uses it as the stop. 以上将其用作停止点。 If this is not desired behavior, change the 35's to 34. 如果这不是您想要的行为,请将35更改为34。

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

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