+ Reply to Thread
Results 1 to 8 of 8

Text to column using formula

  1. #1
    Registered User
    Join Date
    06-05-2014
    Posts
    11

    Text to column using formula

    Hi Guys,

    In excel I'm trying to extract a particular part of text from some html code but the text to column function fails completely with this. I've read many posts that give formula to do this instead but I'm struggling to rewrite one to suit my needs.

    Here is an example one the html codes I'm trying to split. Please consider it in column A1

    <span>
    <H2><!-- mp_trans_rt_start id=""1"" args=""as"" 5 -->Lonsdale Drawstring Carry Sacks<!-- mp_trans_rt_end 5 --></H2><!-- mp_trans_remove_start=""DE,FR,AT"" --><BR>An ideal no-frills solution to transporting your sports equipment or everyday good, the <STRONG>Lonsdale Drawstring Carry Sacks</STRONG> have one large compartment with drawstring closure, finished with Lonsdale branding. <BR><!-- mp_trans_remove_end=""DE,FR,AT"" --><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_start --]> --><BR>&gt; <STRONG>Drawstring sack</STRONG> <BR>&gt; Large compartment <BR>&gt; Drawstring <BR>&gt; Lonsdale branding <BR>&gt; 48cm x 42cm x 11cm<BR><BR><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_end --]> -->
    </span>

    I'm trying to extract the sizing information (48cm x 42cm x 11cm), 2nd and last line from the above string. These sizes vary in how they are written, uses different formats and units and are not always in the same place in the code but are are precursed with "<BR>&gt;" and finished with "<BR>". I tried to use in a formula to split but getting it to work is beyond my limited capabilities.

    Can anyone suggest code that will work and I can drag and drop for the rest of the worksheet?

    Many thanks

    Stephen

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Text to column using formula

    Since the <BR>&gt; tag isn't unique to the size information you can't use those to identify them.

    Since the location, format, and units of the dimensions are different, you can't really use any of that, unless you build a test for each possible case maybe?

    With the information you've given I can't see a formula solution, you haven't defined the input scenario enough for any text excision I can think of.
    Click the [* Add Reputation] Button to thank people for help!
    Post Attachment: Click [Go Advanced] under the reply box; then click [Manage Attachments] to launch the attachments dialogue.
    Mark Thread Solved: Go to the top of the first post; Select [Thread Tools] dropdown; Pick the [Mark thread as Solved] option.

  3. #3
    Registered User
    Join Date
    06-05-2014
    Posts
    11

    Re: Text to column using formula

    Thanks for the reply. Guess I'll spend the next few hours doing it manually urghhhh!

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Text to column using formula

    Quote Originally Posted by ben_hensel View Post
    Since the <BR>> tag isn't unique to the size information you can't use those to identify them.
    Maybe not, but "cm<BR>" is unique at the end, then you just have to work backwards.

    =TRIM(RIGHT(SUBSTITUTE(LEFT(A1,FIND("cm<",A1)+1),"gt; ",REPT(" ",LEN(A1))),LEN(A1)))

  5. #5
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Text to column using formula

    Well really I was hoping you could define the input scenario more, eg, are the units always from the set {cm, in, mm} or something like that; or if they're listed in different places are there like 3 different positions instead of just wherever; or does the text string " x " show up anywhere else (eg, are they always separated by the letter x); if so, then there's still options.

    It's not that it's outright impossible, it's just that the problem isn't defined enough (yet?).


    EDIT:
    Quote Originally Posted by jason.b75 View Post
    Maybe not, but "cm<BR>" is unique at the end, then you just have to work backwards.
    No it's not unique, there could be units other than centimeters used:
    These sizes vary in how they are written, uses different formats and units

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Text to column using formula

    or

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Data Range
    A
    B
    1
    <BR>&gt; Large compartment <BR>&gt; Drawstring <BR>&gt; Lonsdale branding <BR>&gt; 48cm x 42cm x 11cm<BR><BR><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_end --]> -->
    48cm x 42cm x 11cm
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Text to column using formula

    @AlKey, my first thought was similar, but it fails if the first dimension is less than 10cm or more than 999cm, although the latter does seem a little unrealistic in most scenarios.

    Although I think we may have both made the mistake of assuming that all dimensions will be in cm.

    edit:-

    If all first dimensions are between 10 and 999 cm (inclusive) then this one works as well.

    =TRIM(MID(LEFT(A1,FIND("cm<",A1)+1),FIND("cm",A1)-3,100))
    Last edited by jason.b75; 12-04-2015 at 10:13 AM.

  8. #8
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Text to column using formula

    Here is slightly improved formula that will deal with limitations of the first one.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Data Range
    A
    B
    1
    Lonsdale branding <BR>&gt; 48cm x 42cm x 11cm<BR><BR><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_end --]> -->
    48cm x 42cm x 11cm
    2
    Lonsdale branding <BR>&gt; 148cm x 42cm x 11cm<BR><BR><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_end --]> -->
    148cm x 42cm x 11cm
    3
    Lonsdale branding <BR>&gt; 2148cm x 42cm x 11cm<BR><BR><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_end --]> -->
    2148cm x 42cm x 11cm
    4
    Lonsdale branding <BR>&gt; 32548cm x 42cm x 11cm<BR><BR><!-- mp_trans_add=""DE,FR,AT"" <!-- mp_trans_ost_end --]> -->
    32548cm x 42cm x 11cm

+ 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. Replies: 9
    Last Post: 11-08-2015, 08:04 PM
  2. [SOLVED] Need a formula to change cell in column 2 based off of text in column 1
    By bevwalker in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-30-2014, 03:26 PM
  3. Replies: 2
    Last Post: 04-16-2014, 05:13 PM
  4. Need Formula to Match Text In a column And Retrieve adjacent column value
    By excel_joel in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-06-2014, 02:08 AM
  5. [SOLVED] Create formula to sum column total if specific text is present in second column
    By Banir in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-08-2013, 07:48 AM
  6. [SOLVED] Simple formula to match column A, sheet1, with column A, sheet2, return text answer
    By Connie5761 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-14-2012, 02:56 PM
  7. Replies: 1
    Last Post: 04-15-2008, 01:59 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