+ Reply to Thread
Results 1 to 15 of 15

Extracting information from an alphanumeric string

  1. #1
    Registered User
    Join Date
    07-16-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Extracting information from an alphanumeric string

    Hi all,

    Any ideas on how to solve this issue?

    I've got a series of strings with measures of time, all of them with the following structure:

    48 D 21 H 21 M

    each string is returned in a single cell

    Any suggestions on how to convert this info into a single value that could be either days or hours? not manually of course :-)

    Thanks!

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extracting information from an alphanumeric string

    whar does 1 day 3 hrs 5 mins look like ?
    Last edited by martindwilson; 07-16-2012 at 09:27 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    07-16-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extracting information from an alphanumeric string

    It will look like:

    1 D 3 H 5 M

    (thanks for looking into it)

  4. #4
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Extracting information from an alphanumeric string

    If you convert it into a date format, what is the beginning date? the default would be 48 days from 1/1/1900

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extracting information from an alphanumeric string

    totaly wrong answer
    Last edited by martindwilson; 07-16-2012 at 09:36 AM.

  6. #6
    Registered User
    Join Date
    07-16-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extracting information from an alphanumeric string

    I tried the formula above and I got the #VALUE! error

    (I replaced a1 with the relevant cell where my string is located)

  7. #7
    Registered User
    Join Date
    07-16-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extracting information from an alphanumeric string

    If I apply a date format the string does nto change...

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extracting information from an alphanumeric string

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    will give decimal hours

    48 D 21 H 21 M 1173.014583
    1 D 3 H 59 M 27.04097222

  9. #9
    Registered User
    Join Date
    07-16-2012
    Location
    Newcastle upon Tyne
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Extracting information from an alphanumeric string

    =left($a$1,find("d",$a$1)-1)+(mid($a$1,find("d",$a$1)+1,find("h",$a$1)-find("d",$a$1)-2)+mid($a$1,find("h",$a$1)+1,find("m",$a$1)-find("h",$a$1)-2)/60)/24

  10. #10
    Registered User
    Join Date
    07-16-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extracting information from an alphanumeric string

    martindwilson solution worked like a charm!

    (stunn soution give the same error as martin's first try)

    Tlanks a lot for your help solving the issue

  11. #11
    Registered User
    Join Date
    07-16-2012
    Location
    Newcastle upon Tyne
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Extracting information from an alphanumeric string

    For 48 D 21 H 21 M my solution gives 48.88958333, Martin's gives 1173.015
    For 1 D 3 H 5 M my solution gives 1.12847222, Martin's gives 27.00347

    Mine is in days, Martin's is almost in hours.

    Hours would actually be: 1173.35 and 27.08333

    If mine is giving you an error, perhaps you have multiple spaces between letters and numbers?
    Last edited by stunn; 07-16-2012 at 10:12 AM.

  12. #12
    Registered User
    Join Date
    07-16-2012
    Location
    Newcastle upon Tyne
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Extracting information from an alphanumeric string

    You can test this by typing =48+time(21,21,0) and formatting the cell as numeric to see the answer in days.
    =(48+TIME(21,21,0))*24 shows it in hours.

  13. #13
    Registered User
    Join Date
    07-16-2012
    Location
    Newcastle upon Tyne
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Extracting information from an alphanumeric string

    Try this instead:
    =TRIM(LEFT($A1,FIND("D",$A1)-1))+(TRIM(MID($A1,FIND("D",$A1)+1,3))+TRIM(MID($A1,FIND("H",$A1)+1,3))/60)/24

    However, I should note that this could cause more problems than it solves if you do have multiple spaces. Simply because it only looks at the first three characters after D and H. So, although "48 D 21 H 21 M" would still work, "48 D 21 H 21 M" would not.

    Possibly the safest option would be:
    =TRIM(LEFT($A1,FIND("D",$A1)-1))+(TRIM(MID($A1,FIND("D",$A1)+1,FIND("H",$A1)-FIND("D",$A1)-1))+TRIM(MID($A1,FIND("H",$A1)+1,FIND("M",$A1)-FIND("H",$A1)-1))/60)/24
    Last edited by stunn; 07-16-2012 at 10:29 AM.

  14. #14
    Registered User
    Join Date
    07-16-2012
    Location
    Newcastle upon Tyne
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Extracting information from an alphanumeric string

    It looks like the forum editor automatically removed the multiple spaces from my examples! I'll use ^ instead. "48^D^21^^H^21^^M" would work, and "48^D^^21^H^^21^M" would not.

  15. #15
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extracting information from an alphanumeric string

    yep mine is wrong it should give decimal of hours not days so 5 minutes = 5/60
    =TRIM(LEFT($A1,FIND("D",$A1)-1))*24+TRIM(MID($A1,FIND("D",$A1)+1,3))+TRIM(MID($A1,FIND("H",$A1)+1,3))/60


    48 D 21 H 30 1173.5
    1 D 3 H 59 M 27.98333333
    mind you
    48^D^21^^H^21^^M" would work, and "48^D^^21^H^^21^M"
    why would there be more than 2 digits in the hours slot?
    Last edited by martindwilson; 07-16-2012 at 04:54 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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