+ Reply to Thread
Results 1 to 7 of 7

Extracting Specific Values from a Text string

  1. #1
    Forum Contributor
    Join Date
    09-03-2004
    Location
    Vancouver, BC Canada
    Posts
    136

    Extracting Specific Values from a Text string

    Hi there,
    I'm trying to extract data from an Account code cell. Example of an account code in my data is as follows:
    310410-01-1-000

    Starting from left to right:
    The first 6 characters are the basic account code ( In this example 310410)
    The 2 characters to the right of the first Hyphen are (Location codes)- In this example it is 01
    The single character to the right of the second Hyphen is the Department code, which is "1" in this example.

    I'm trying to extract the Location code and department code in 2 separate columns. I have tried using the following formula:
    =MID(C2,FIND("-",C2)+1,2) - Cell C2 refers to the cell holding the entire account code.

    By doing so I'm able to extract the Location but not the Department.

    Could some one please help me? If my explanation is insufficient and/or incomplete then I will try and explain myself better.

    Thank you one and all for the help rendered.

    Cheers,
    SJ

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Extracting Specific Values from a Text string

    Are they always the same length? How do they vary?
    If they don't vary, then
    =MID(A1, 8,2)
    =MID(A1, 11,1)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Extracting Specific Values from a Text string

    If they do vary but second value is always 1 character and always to the right of second hyphen, then

    =MID(C2, FIND("^", SUBSTITUTE(C2, "-","^",2))+1,1)

  4. #4
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Extracting Specific Values from a Text string

    With the account in D3 this worked to get the location:
    Please Login or Register  to view this content.
    and this to get the department:
    Please Login or Register  to view this content.
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  5. #5
    Forum Contributor
    Join Date
    09-03-2004
    Location
    Vancouver, BC Canada
    Posts
    136

    Re: Extracting Specific Values from a Text string

    Hi ChemistB,
    Yes the length always remains the same, and the solution was quick and simple. Much appreciated.
    Thank you and have a great day!

    Cheers,SJ

  6. #6
    Forum Contributor
    Join Date
    09-03-2004
    Location
    Vancouver, BC Canada
    Posts
    136

    Re: Extracting Specific Values from a Text string

    Thanks Nigelbloomy!
    It worked..

    Cheers,SJ

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Extracting Specific Values from a Text string

    Hi kollur,

    This is a trick I learned a few years ago. I call it "blowing up using spaces" and then trim to get the parts.

    =TRIM(MID(SUBSTITUTE($A2,"-",REPT(" ",LEN($A2))),1+(COLUMNS($A:A)-1)*LEN($A2),LEN($A2)))

    The above formula will replace all the dashes with a bunch of spaces. Then the Mid function grabs each piece and the trim knocks off the extra spaces. See the attached and how it works on your problem.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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: 2
    Last Post: 11-18-2014, 06:26 AM
  2. Extracting Specific Words from string
    By janagan in forum Excel General
    Replies: 3
    Last Post: 08-23-2013, 12:57 AM
  3. Extracting numbers and text from inconsistent text/number formatted string
    By Brandivil in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-25-2013, 01:46 PM
  4. [SOLVED] Extracting specific part of the text string to another column
    By ssanjju in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 01-20-2013, 07:20 PM
  5. [SOLVED] Extracting a specific string from all cells?
    By wearwestern in forum Excel General
    Replies: 3
    Last Post: 10-25-2012, 03:22 PM
  6. extracting a specific value from a string
    By xiao_gosu in forum Excel General
    Replies: 16
    Last Post: 04-24-2010, 03:38 PM
  7. extracting values in a specific text
    By darkhangelsk in forum Excel General
    Replies: 8
    Last Post: 08-18-2009, 11:02 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