+ Reply to Thread
Results 1 to 6 of 6

Formula Finding String with Specific Letters and Numbers

  1. #1
    Registered User
    Join Date
    06-01-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Formula Finding String with Specific Letters and Numbers

    Say I have these two lines in Column A:

    3051S2TG4A2A11X5AWA3WK1I5A1140
    3051S2LD2AA1A1030DFF71CA00


    I need to be able to have a formula in Column B that Finds the letter "A" when it is followed by four numbers, and then return "A and the 4 numbers."

    So for the first line, the result in Column B would be "A1140," and the second line result would be "A1030"

    Any help would be much appreciated.

    Thanks,
    J

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula Finding String with Specific Letters and Numbers

    Array formula, must be confirmed with Shift Ctrl Enter

    =MID(A2,MATCH(1,(MID(A2,ROW($A1:$A255),1)="A")*ISNUMBER(--MID(A2,ROW($A2:$A256),4)),0),5)
    Last edited by jason.b75; 07-06-2012 at 06:25 PM.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula Finding String with Specific Letters and Numbers

    Great formula, Jason.

    Here's a recommended adjustment to reduce the number of calculations per cell from 500 to just number of letters per cell.

    =MID(A2,MATCH(1,(MID(A2,ROW(INDIRECT("$1:$" & LEN(A2)-4)),1)="A")*ISNUMBER(--MID(A2,ROW(INDIRECT("$2:$" & LEN(A2)-3)),4)),0),5)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula Finding String with Specific Letters and Numbers

    I thought about that Jerry, but depending on the number of records it can be false economy.

    I've tweaked the formula to reduce the number of precedent cells, something I've tried to get into the habit of is avoiding volatile functions unless it is known that the record count is fairly low.

    Maybe that's just the result of being over-exposed to the suggestions of a certain over-confident MVP in another forum.
    Last edited by jason.b75; 07-06-2012 at 06:34 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Formula Finding String with Specific Letters and Numbers

    The problem with not using INDIRECT in that formula is that it will change if you insert rows above row 255. That wouldn't cause a problem here, but inserting rows above row 1 would.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula Finding String with Specific Letters and Numbers

    Lots of good warnings with each approach.

    I would guess the real benefit is to use whatever formula works, then use a COPY>PASTESPECIAL>VALUES to remove the formulas and leave the extracted code behind. Makes either method safe to employ short term.


    @JPedges38 - If these take care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

+ 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