+ Reply to Thread
Results 1 to 8 of 8

Puzzling - Extract the word with PH- in it, start, middle or end of cell location

Hybrid View

vkingxl Puzzling - Extract the word... 07-01-2018, 10:53 PM
FDibbins Re: Puzzling - Extract the... 07-01-2018, 11:04 PM
vkingxl Hi there, the formula works... 07-01-2018, 11:27 PM
FDibbins Re: Puzzling - Extract the... 07-01-2018, 11:37 PM
FlameRetired Re: Puzzling - Extract the... 07-02-2018, 12:16 AM
samba_ravi Re: Puzzling - Extract the... 07-02-2018, 01:22 AM
vkingxl Re: Puzzling - Extract the... 07-02-2018, 12:17 PM
FlameRetired Re: Puzzling - Extract the... 07-02-2018, 04:20 PM
  1. #1
    Registered User
    Join Date
    11-08-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12

    Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    Hi guys,

    I've been working on this for hours, searching google and threads but I just can't get it to work.
    I need to extract the text in a cell, but not everyone puts it in the same place. Not only that, but the PH- value length is variable.

    This works if it's the first word in the cell, and a space following it, but 10% of my list is not so simple:
    =MID(B2,FIND("PH-",B2)-(FIND("PH-",B2)-1),FIND(" ",B2)-1)

    And this formula is working great in my tests, except that I can't figure out how to count the location of the word with PH- in it, so it only works if I manually do it (see attached file for example) - any help would be appreciated!

    =TRIM(MID(SUBSTITUTE(B2," ",REPT(" ",LEN(B2))),(C2-1)*LEN(B2)+1, LEN(B2)))

    I'm not sure if the attachment is working, so here is the formula:
    Result Source word location formula
    52PH-1233 52PH-1233 1 TRIM(MID(SUBSTITUTE(B2," ",REPT(" ",LEN(B2))),(C2-1)*LEN(B2)+1, LEN(B2)))
    52PH-12345 Crazy but 52PH-12345 3 TRIM(MID(SUBSTITUTE(B3," ",REPT(" ",LEN(B3))),(C3-1)*LEN(B3)+1, LEN(B3)))
    52PH-1235 52PH-1235 and 1 TRIM(MID(SUBSTITUTE(B4," ",REPT(" ",LEN(B4))), (C4-1)*LEN(B4)+1, LEN(B4)))
    522PH-1233 120 522PH-1233 then 2 TRIM(MID(SUBSTITUTE(B5," ",REPT(" ",LEN(B5))), (C5-1)*LEN(B5)+1, LEN(B5)))
    Attached Files Attached Files

  2. #2
    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
    53,048

    Re: Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    Whats wrong with the formula you have there?
    can you show some samples where it doesnt work?
    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

  3. #3
    Registered User
    Join Date
    11-08-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12
    Quote Originally Posted by FDibbins View Post
    Whats wrong with the formula you have there?
    can you show some samples where it doesnt work?
    Hi there, the formula works if i manually put the word location in the c column. But i download a new file every day with over 200 lines. If i can figure out a way to automatically determine which word in the cell has the "PH-" value in it, that's perfect.

  4. #4
    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
    53,048

    Re: Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    This will give you the starting position of the phrase 52PH....
    =SEARCH("ph",B2)-2

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    Maybe this:


    A
    B
    C
    1
    Source
    2
    52PH-1233
    52PH-1233
    In b2: =TRIM(LEFT(SUBSTITUTE(TRIM(MID(" "&A2,SEARCH("ph-"," "&A2)-3,100))," ",REPT(" ",100)),100))
    3
    Crazy but 52PH-12345
    52PH-12345
    4
    52PH-1235 and
    52PH-1235
    5
    120 522PH-1233 then
    522PH-1233
    Dave

  6. #6
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,937

    Re: Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    Or
    a2=trim(right(substitute(left(b2,search(" ",b2&" ",search("ph",b2))-1)," ",rept(" ",256)),256))
    TRY THIS AND COPY TOWARDS DOWN
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  7. #7
    Registered User
    Join Date
    11-08-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12

    Re: Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    Thanks so much guys for such quick help! I love a puzzle just as much as the next guy, but at some point the banging of head against the keyboard stops being fun.

    Fdibbins - your solution was almost there, but wasn't working on the sequences with more than 2 prefix before the PH-

    FlameRetired - BEST SOLUTION - I tried this formula on my data sequence and it found the results almost every time, even when there were asterisk in front of the PH-, the only time it didn't work was if they didn't have any prefix included in front of the PH- and that was hardly any. So thank you soo much sir!!

    nflsales - THANKS for your suggestions as well. Your's worked 8-10 times, but I still would have to do a bit of cleanup, and it did pick up those couple that Dave's missed. A good second option to have available.

    I'll save these to my OneNote excel cheat sheet as I'm sure I'll be needing them again. Thanks again EVERYONE. Really appreciate the help!!

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Puzzling - Extract the word with PH- in it, start, middle or end of cell location

    You're welcome. Thanks for the feedback and marking your thread Solved.

+ 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. Extract data from middle of cell
    By ajhat in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-24-2014, 04:17 AM
  2. Extract data from middle of cell
    By ajhat in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-23-2014, 10:04 AM
  3. [SOLVED] Extract number in middle of cell
    By SCOOBYDOO in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  4. [SOLVED] Extract number in middle of cell
    By SCOOBYDOO in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. [SOLVED] Extract number in middle of cell
    By SCOOBYDOO in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  6. Extract number in middle of cell
    By SCOOBYDOO in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  7. Extract number in middle of cell
    By SCOOBYDOO in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-09-2005, 11:05 AM

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