从Excel中的字符串中拆分子字符串

时间:2016-10-13 18:48:04

标签: excel excel-vba macros excel-formula excel-2007 vba

例如,这是单元格A1中的字符串:

产品图片文件:2eeb_1_b__57081.JPG

产品图片网址:http://www.example.com/product_images/p/759/2eeb_1_b__57081.JPG

产品图片文件:r__06677.jpg

产品图片网址:http://www.example.com/product_images/e/130/r__06677.jpg

它包含我要填充的两个图像URL这两个URL在单元格B1和C1中。

2 个答案:

答案 0 :(得分:1)

B1中输入此公式:

=IFERROR(MID($A1,
SEARCH("http:",$A1),
SEARCH(".jpg",$A1,SEARCH("http:",$A1))
-SEARCH("http:",$A1)+LEN(".jpg")),"")

C1中输入此公式:

=IFERROR(MID(SUBSTITUTE($A1,$B1,""),
SEARCH("http:",SUBSTITUTE($A1,$B1,"")),
SEARCH(".jpg",SUBSTITUTE($A1,$B1,""),
SEARCH("http:",SUBSTITUTE($A1,$B1,"")))
-SEARCH("http:",SUBSTITUTE($A1,$B1,""))+LEN(".jpg")),"")

D1中输入此公式:

=IFERROR(MID(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),
SEARCH("http:",SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,"")),
SEARCH(".jpg",SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),
SEARCH("http:",SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,"")))
-SEARCH("http:",SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""))+LEN(".jpg")),"")

E1中输入此公式:

=IFERROR(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),
SEARCH("http:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,"")),
SEARCH(".jpg",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),
SEARCH("http:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,"")))
-SEARCH("http:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""))+LEN(".jpg")),"")

以及F1中的此公式:

=IFERROR(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),$E1,""),
SEARCH("http:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),$E1,"")),
SEARCH(".jpg",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),$E1,""),
SEARCH("http:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),$E1,"")))
-SEARCH("http:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,$B1,""),$C1,""),$D1,""),$E1,""))+LEN(".jpg")),"")

答案 1 :(得分:0)

设b1 =左(a1,150);设置c1 =右(a1,150)
(以最佳长度玩150)

在b1 / c1中粘贴特殊值/值

B1:找* url:并替换为

B1:找到jpg *并用jpg替换

C1:find * url:并替换为

您可以对B列和C列执行此操作,而不仅仅是单元格。