+ Reply to Thread
Results 1 to 7 of 7

Extracting Numbers from a Alphanumeric String

  1. #1
    Registered User
    Join Date
    03-04-2013
    Location
    a
    MS-Off Ver
    Excel 2003
    Posts
    10

    Extracting Numbers from a Alphanumeric String

    Hello,

    I need to extract the numbers that appear in the attached CSV sample. This is what has been extracted from a database.
    The numbers 1 to 12 at the end of the string are the months of the year. The numbers beside that are duty hours. So Person Doug Smith did 119:22 duty hours in January.

    How can I extract the numbers into different columns?

    Row Titles would be:

    CREW NAME¦¦Jan¦¦Feb¦¦March¦¦etc
    Doug smith
    Total hours¦¦Jan

    crewname;"time_format(SEC_TO_TIME(sum(TIME_TO_SEC(dutyhours))) '%H:%i')";"month(date)"
    Douglas Smith;"119:22";"1"
    Douglas Smith;"127:33";"2"
    Douglas Smith;"138:31";"3"
    Douglas Smith;"117:55";"4"
    Douglas Smith;"133:27";"5"
    Douglas Smith;"124:10";"6"
    Douglas Smith;"152:35";"7"
    Douglas Smith;"152:25";"8"
    Douglas Smith;"90:53";"9"
    Douglas Smith;"130:28";"10"
    Douglas Smith;"123:06";"11"
    Douglas Smith;"131:34";"12"
    Simon Clare;"130:43";"1"
    Simon Clare;"129:31";"2"
    Simon Clare;"125:04";"3"
    Simon Clare;"152:03";"4"
    Simon Clare;"127:20";"5"
    Simon Clare;"87:11";"6"


    Would be great to get some help before tomorrow morning.

    Thanks martin
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Extracting Numbers from an Alphanumeric String

    Put the following function in B2 then copy and paste it down through Column B

    =MID(A2,FIND(";",A2,1)+2,FIND(";",A2,FIND(";",A2,1)+1)-FIND(";",A2,1)-3) & ":" & MID(A2,FIND(";",A2,FIND(";",A2,1)+1)+2,LEN(A2)-FIND(";",A2,FIND(";",A2,1)+1)-2)


    Edit - Add on
    The above will give you a number in the format 119:22:1
    to extract the numbers to separate columns
    C2 .... =VALUE(LEFT(B2,FIND(":",B2,1)-1))
    D2..... =VALUE(MID(B2,FIND(":",B2,1)+1,FIND(":",B2,FIND(":",B2,1)+1)-FIND(":",B2,1)-1))
    E2..... =VALUE(RIGHT(B2,LEN(B2)-FIND(":",B2,FIND(":",B2,1)+1)))


    Then paste them all down through the length of the table.
    Last edited by AndyLitch; 03-31-2013 at 04:22 PM. Reason: Additional info
    Elegant Simplicity............. Not Always

  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,946

    Re: Extracting Numbers from an Alphanumeric String

    Or you could high-light the range of data and use text-to-columns/delimited/semicolon

    Andy's results will be text, so they will need to be converted to values before you can use them
    Last edited by FDibbins; 03-31-2013 at 04:06 PM.
    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
    Registered User
    Join Date
    04-13-2012
    Location
    Leeds, UK
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Extracting Numbers from a Alphanumeric String

    Open file -> Import Wizard* -> Choose 'Delimited', click Next -> use ';' as the delimiter


    *I think, I can't remember if that's what it's called.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Extracting Numbers from a Alphanumeric String

    Here's what I did to get what you're asking for...

    • Change the file extension of the CSV file to .TXT
    (it really isn't a Comma Separate Value file...It's a Semicolon Separated Value file)
    • Import the file to Excel....Data.From_Text
    ...Check: Delimited...Click: Next
    ...Check: Semicolon..Click: Next
    ...Click: Finish
    ...Select a destination...Click: OK

    • Edit the column headings, if necessary
    • Select the data area
    • Insert.Pivot_Table.Pivot_Table
    ...Choose a location...Click: OK
    • Drag Crewname to ROWS
    • Drag Month to COLUMNS
    • Drag time_format to VALUES
    ...Click the dropdown and change the function from COUNT to SUM.

    Now you have a pivot table with
    ...Months across the top
    ...Crewnames down the left side
    ...Hours/minutes for values
    ...Totaled at the bottom

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  6. #6
    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,946

    Re: Extracting Numbers from a Alphanumeric String

    Martin please do not post duplicate threads...

    http://www.excelforum.com/excel-form...html?p=3179745

    I have closed your other thread, you can continue on this 1

  7. #7
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Extracting Numbers from a Alphanumeric String

    Hi martinhardy

    Here is a formula approach, but Ron's is a better idea!
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

+ 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