Search code examples
excelmacrosexcel-formulaexcel-2007vba

Split the Sub-String from a String in Excel


For Example Here is the String in Cell A1:

Product Image File: 2eeb_1_b__57081.JPG

Product Image URL: http://www.example.com/product_images/p/759/2eeb_1_b__57081.JPG

Product Image File: r__06677.jpg

Product Image URL: http://www.example.com/product_images/e/130/r__06677.jpg

It Contains two Image URLs I want to Populate These two URLs in Cell B1 and C1.


Solution

  • Enter this formula in B1:

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

    Enter this formula in 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")),"")
    

    Enter this formula in 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")),"")
    

    Enter this formula in 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")),"")
    

    and this formula in 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")),"")