+ Reply to Thread
Results 1 to 8 of 8

Delete everything BEFORE and AFTER a certain string of characters, including string itself

  1. #1
    Registered User
    Join Date
    07-24-2014
    Location
    Canada
    MS-Off Ver
    Office 365 Home Premium
    Posts
    6

    Delete everything BEFORE and AFTER a certain string of characters, including string itself

    Hi all,

    I'll try my best to describe the task I'm trying to do in Excel. Any help would be much appreciated...

    I have an exported html bookmarks file. Each cell contains a URL as well as a bunch of html code before and after the URL. I need to remove everything except the URL from each cell (i.e. delete everything before the start of the URL and after the end of it).

    Example of a cell (URL is in quotation marks following HREF=):

    <DT><A HREF="http://www.google.ca/search?q=funny+cartoons&hl=en&site=webhp&prmd=imvns&tbm=isch&tbo=u&source=univ&sa=X&ei=5DfsToP2PMLL0QGdvsCpCQ&sqi=2&ved=0CCgQsAQ&biw=1399&bih=779" ADD_DATE="1324103767">funny cartoons (images) - Google Search</A>


    Desired result:

    http://www.google.ca/search?q=funny+...w=1399&bih=779


    I'm a novice with Excel formulas. My first thinking was to somehow combine two separate formulas that would do the following, respectively:

    1) Delete everything preceding "http" (this would also allow any link beginning with https to be affected correctly)
    2) Delete everything from "ADD_DATE" onward, including "ADD_DATE" itself plus 2 characters before it (to eliminate the quotation mark at the end of the URL and the space)

    It doesn't matter at all if the formula is placed in the actual cell, or in the cell next to it. I will be copying and pasting the post-formula results to a different location.

    Really looking forward to your help with this - in implementing either a 2-part formula like I suggested, or perhaps a simpler, more efficient approach you can think of to achieve the same result.

    Thanks in advance!

    Ed

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    In A1 Cell

    <DT><A HREF="http://www.google.ca/search?q=funny+cartoons&hl=en&site=webhp&prmd=imvns&tbm=isch&tbo=u&source=univ&sa=X&ei=5DfsToP2PMLL0QGdvsCpCQ&sqi=2&ved=0CCgQsAQ&biw=1399&bih=779" ADD_DATE="1324103767">funny cartoons (images) - Google Search</A>

    In B1 Cell

    =IFERROR(REPLACE(REPLACE(A1,1,FIND("//",A1)+1,""),FIND("ADD_DATE",REPLACE(A1,1,FIND("//",A1)+1,""))-2,5^5,""),"")


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    Hi and welcome to the forum

    For future reference, please upload a sample workbook to the forum, it makes it much easier to test with.

    Having said that, if the data is in A1, put this in B1 and copy down...
    =MID(A1,SEARCH("http",A1,1),SEARCH("add_",A1,1)-SEARCH("http",A1,1)-2)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    assuming the whole string is stored in Cell B4, try the following formula in the cell where you desire the result:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    jewel, I think the "" was inserted to show us where to start and end, plus I saw 2 sets of them (could be wrong though lol)

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    oops! I thought that was an integral part of the string. If it was just to show where the URL detail is, then I simply misunderstood it.

    As for 2 (or more) sets of quotes - the suggested formula should simply extract what's between the 1st set, and discard everything else including any further set of double quotes.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    I guess we will have to wait to hear back from the OP

  8. #8
    Registered User
    Join Date
    07-24-2014
    Location
    Canada
    MS-Off Ver
    Office 365 Home Premium
    Posts
    6

    Re: Delete everything BEFORE and AFTER a certain string of characters, including string it

    Thank you all for your responses! I've had a chance to try the solution provided by sixthsense so far. It worked perfectly - well, almost perfectly. It leaves out the http:// part of the URL. However, with the way browsers work now, that doesn't matter. When the URL is made clickable using =HYPERLINK it works just fine without the http://

    FDibbins, thanks for pointing that out. I will gladly include a sample workbook with future questions. I haven't had time to try the other solutions yet but will as soon as I can. In the meantime I will keep using the first one.

    Thank you again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. delete last 5 characters from string
    By leooconnor in forum Excel General
    Replies: 6
    Last Post: 01-02-2015, 08:50 PM
  2. [SOLVED] Backspace event text box string formatting not able to delete characters
    By Code Flunkie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2014, 04:30 PM
  3. Replies: 4
    Last Post: 12-08-2010, 01:28 PM
  4. Replies: 5
    Last Post: 05-15-2006, 01:15 PM
  5. Replies: 0
    Last Post: 08-29-2005, 11:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1