+ Reply to Thread
Results 1 to 7 of 7

Extracting text from Excel cells

  1. #1
    Registered User
    Join Date
    09-15-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    42

    Extracting text from Excel cells

    Hello,

    I am working on a personal file for my fantasy football league. we do all of the stats by hand and dont use one of the major websites to manage our league for us.

    here is the data I need to work with

    Vick 29COM-317YDS 2TD 4INT 7CAR-32YDS 32PTS
    A. Rodgers 30COM-303YDS 2TD 1INT 2PTS 5CAR-27YDS 39PTS
    E. Manning 21COM-213YDS 1TD 16PTS

    I have two things i need to do with this data.
    1. I need to pull each players name out and copy it into a new cell
    2. I need to pull out how many points they scored without the "PTS" at the end of it

    The problem I am running into with the first one is the names vary in length. Is there a way I can pull out everything before the first number?
    The second problem I think I have figured out.

    B2=right(A2,5)
    C2=Left(B2,2)
    I would then hide B2.
    It works but Is there a way to do it without the extra column?

    Thanks

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

    Re: Extracting text from Excel cells

    Hi DRFILL

    Assuming data is in a A1, to return the names.

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

  3. #3
    Registered User
    Join Date
    09-15-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Extracting text from Excel cells

    It works. thank you. But I don't fully understand how it works.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Extracting text from Excel cells

    @Kevin, there is no reason to call the Find function twice:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

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

  5. #5
    Registered User
    Join Date
    09-15-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Extracting text from Excel cells

    can you explain the difference between your code and the one Kevin gave please?

    I like understanding what I am doing in my file and not just putting code in that works but I have no clue how it works.

    thanks

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Extracting text from Excel cells

    Really, both formulas do the same thing. They find the first number in the text string that A1 holds and return its position in the string, and then use that position to return everything to the left of it, minus the number itself and the preceding space.

    You can see the formula working in action by using the Evaluate Formula tool (should be in the Formulas tab of the ribbon).

    However, here is a step-by step breakdown using this example string:
    Vick 29COM-317YDS 2TD 4INT 7CAR-32YDS 32PTS


    =LEFT(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890))-2)
    The Find locates a string within another string. (Note on Find: it is case sensitive, so if you use =Find("A","abc") the result will be an error. To have a find function that is not case sensitive, use Search() instead. See Excel help for more information. We are using Find because numbers don't have a case, so there is no issue.)
    The first argument, {1,2,3,4,5,6,7,8,9,0}, is what is being found
    The second argument, A1&1234567890, is where the function is looking.
    The curly braces {} tell the formula that we're looking for more than one item. The technical term is array. We are telling the find function to look for an array of items. Find will error if it can't find the criteria though, so to prevent errors we are guaranteeing that every item (in this case, the numbers 0 though 9) can be found at least once by adding the number 1234567890 to the end of the text of A1.

    So, at this stage in the formula:
    FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890) -->
    FIND({1,2,3,4,5,6,7,8,9,0},Vick 29COM-317YDS 2TD 4INT 7CAR-32YDS 32PTS1234567890) -->

    First 1 Found: 13 (the thirteenth character in the string is a 1)
    First 2 Found: 6 (the sixth character in the string is a 2)
    First 3 Found: 12 (the twelfth character in the string is a 3)
    First 4 Found: 23 (the twenty-third character in the string is a 4)
    First 5 Found: 48 (the forty-eighth character in the string is a 5)
    First 6 Found: 49 (the forty-ninth character in the string is a 6)
    First 7 Found: 14 (the fourteenth character in the string is a 7)
    First 8 Found: 51 (the fifty-first character in the string is a 8)
    First 9 Found: 7 (the seventh character in the string is a 9)
    First 0 Found: 53 (the fifty-third character in the string is a 0) -->

    So the Find portion returns this array of values: {13,6,12,23,48,49,14,51,7,53}

    Now steps in the Min part:
    =LEFT(A1,MIN({13,6,12,23,48,49,14,51,7,53})-2)
    The minimum of that array of values is 6. This means that the first number encountered in that text is at position 6. Looking at the string again, we can manually verify this because the number 2 is the 6th character in the string:
    Vick 29COM-317YDS 2TD 4INT 7CAR-32YDS 32PTS

    So now all that remains the Left function:
    =LEFT(A1,6-2)

    This simply says we want the left 6 characters, minus 2 (because we don't actually want to see the found number, so that is -1, and we also don't want the space between "Vick" and the number, so that is why it is -2), which leaves us with just "Vick".

    I hope that makes sense.

  7. #7
    Registered User
    Join Date
    09-15-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Extracting text from Excel cells

    Wow, thank you. That makes perfect sense. the way you put it makes it seem very simple.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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