Excel公式获取2个字符之间的字符串 [英] Excel formula to get string between 2 characters

查看:1176
本文介绍了Excel公式获取2个字符之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用公式在Excel中2个字符之间动态提取字符串(无文本到列).样本数据为:

I'm trying to dynamically extract the string between 2 characters in Excel using a formula (no text to columns). The sample data is:

US - Blue Widgets - Net
UK - Green - Grass
UAE - Red - Apples

*请注意,数据没有固定长度

* Note that the data doesn't have fixed length

我尝试使用公式,但是我想我缺少一些东西,因为它还会在最后一个-之后返回字符串.

I tried using a formula, but I think I'm missing something because that also returns the string after the last -.

公式:

=TRIM(LEFT(SUBSTITUTE(MID(A2,FIND("|",SUBSTITUTE(A2,"-","|",1))+1,LEN(A2)),"_",REPT(" ",LEN(A2))),LEN(A2)))

这返回的是:

Blue Widgets - Net
Green - Grass
Red - Apples

这是我希望它返回的内容:

here's what I'd like it to return:

Blue Widgets
Green
Red

推荐答案

尝试一下:

=TRIM(MID(A2, 6, FIND("-",A2,6) - FIND("-",A2) - 2))

如果硬编码6无效,则可以将其替换为FIND(-",A2)+ 1.

If hard coded 6 is not ok, you can replace it with FIND("-", A2) + 1.

这篇关于Excel公式获取2个字符之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆