+ Reply to Thread
Results 1 to 9 of 9

Search for a text string contained within a cell & copy to adjacent cell

  1. #1
    Registered User
    Join Date
    06-11-2020
    Location
    Perth, Australia
    MS-Off Ver
    2016
    Posts
    1

    Search for a text string contained within a cell & copy to adjacent cell

    Hello, new to the forum and need either a formula or macro to do the following.
    Essentially, I have a list of record titles, for example:

    John's ID is DPC1234
    Steve's ID is DPC5432
    Mary's first ID was DPC6543 but her new ID is DPC8765
    Phil's ID was DPC9635 but was changed to DPC9646 on May 30

    The titles above would be contained in cells A1 to A4. What I want to do is extract all the ID numbers and copy those numbers to the adjacent cells in column B. The adjacent cells would then look like:

    DPC1234
    DPC5432
    DPC6543 DPC8765
    DPC9635 DPC9646

    All IDs have the same DPC prefix. Is this possible with a formula or macro?
    Thank you in advance.

  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
    52,933

    Re: Search for a text string contained within a cell & copy to adjacent cell

    Do they all always star with D?

    oops never mind, you already said that
    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
    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,933

    Re: Search for a text string contained within a cell & copy to adjacent cell

    Try this in B1, copied down...
    =MID(A1,SEARCH("DPC",A1),7)&IF(LEN(A1)-LEN(SUBSTITUTE(A1,"DPC",""))>3,","&MID(A1,SEARCH("DPC",A1,SEARCH("DPC",A1)+1),7),"")

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Search for a text string contained within a cell & copy to adjacent cell

    Assuming your text is never longer than 300 characters (if it can be, increase the three 300's to a value as large or larger than the longest possible length), you can use this formula...

    =TEXT(LEFT(TRIM(MID(SUBSTITUTE($A1,"DPC",REPT(" ",300)),COLUMNS($B:B)*300,300)),4),"""DPC""0000")

  5. #5
    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,933

    Re: Search for a text string contained within a cell & copy to adjacent cell

    Rick that only gets the 1st 1, some have 2 IDs

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Search for a text string contained within a cell & copy to adjacent cell

    I forgot to mention... put the formula I posted in the first output cell (I presume that would be B1), then copy it across for as many columns as the maximum number of IDs as the OP thinks will ever be necessary, then copy all of those down to the end of the data (or below).
    Last edited by Rick Rothstein; 06-12-2020 at 01:29 AM.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Search for a text string contained within a cell & copy to adjacent cell

    The OP seems to want the results in one cell in B, though.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Search for a text string contained within a cell & copy to adjacent cell

    Hmm! I misread "adjacent cells in column B" to mean "adjacent cells" starting "in column B".
    Last edited by Rick Rothstein; 06-12-2020 at 02:45 AM.

  9. #9
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Search for a text string contained within a cell & copy to adjacent cell

    Okay, in an attempt to redeem myself how about this macro solution (which will handle as many IDs as there might be)...
    Please Login or Register  to view this content.

+ 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. [SOLVED] Search for a text string and return given text string to adjacent cell
    By hecgroups in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-14-2015, 04:50 AM
  2. [SOLVED] Search for a string and retrieve string from an adjacent cell.
    By djt80 in forum Excel General
    Replies: 5
    Last Post: 01-27-2015, 03:57 PM
  3. Search column for string and date then search adjacent cell and pop up message
    By ftwobtwo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2014, 09:55 AM
  4. [SOLVED] Search for the first cell that contained a specific text
    By Dena in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-17-2014, 01:46 PM
  5. [SOLVED] Search for string, copy adjacent cell
    By omaolain in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-05-2014, 10:44 AM
  6. [SOLVED] Copy any bold text within a cell text string to an adjacent cell
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-31-2014, 06:22 PM
  7. Search for a text string and return adjacent cell value for each match
    By ral8088 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-21-2013, 09:55 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