Results 1 to 10 of 15

Thread: Extracting Custom Pattern Consisting of Numbers & Text From Alphanumeric String

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    what about the PM you sent me? The last one here has 4 characters (TCIA)

    Details appear in a number of different ways e.g.
    1.MEDIA VISION DE PA 2000679547,2000679548,2000685031,2000685031,200068 5031 SKY
    2.SVERIGESTELEVISIOLBC64745/01AGRREF810130423100000835
    3.AVJET INTERNATIONA INV NO.TCIA12539/01 TCA12540/01TCI12538/01
    I'd like to be able to return the following..
    1. 2000679547 2000679548 2000685031 2000685031 2000685031
    2. LBC64745/01
    3. TCIA12539/01 TCA12540/01 TCI12538/01

    I'd just love one excel formula to return the following results if possible

    Can anyone help?
    Cheers
    Larkspur
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Please ignore the TCIA, typing error

    Quote Originally Posted by Excel Fox View Post
    what about the PM you sent me? The last one here has 4 characters (TCIA)

  3. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by larkspur View Post
    Please ignore the TCIA, typing error
    I'm sure Excel Fox won't mind if I jump in here. Based on your previous descriptions of your invoice numbers and what your data column values look like couple with how you want the data split out, I have a UDF (user defined function) for you to consider (I could not think of anyway to do it with normal Excel functions)...
    Code:
    Function InvoiceNumbers(Cell As Range) As String
      ' This function assumes output will start one cell to the right of the specified Cell argument
      Dim X As Long, Index As Long, S As String, OutText As String
      S = Cell.Text
      For X = 1 To Len(S)
        If Mid(S, X, 11) Like "[A-Za-z][A-Za-z][A-Za-z]#####/##" Then
          OutText = OutText & " " & Mid(S, X, 11)
        ElseIf Mid(S, X, 10) Like "2000######" Or Mid(S, X, 10) Like "1800######" Then
          OutText = OutText & " " & Mid(S, X, 10)
        End If
      Next
      Index = Application.Caller.Column - Cell.Column - 1
      If Len(S) Then InvoiceNumbers = Split(Trim(OutText) & Space(Len(S)))(Index)
    End Function
    Assuming your data starts in cell A1, put this formula...

    =InvoiceNumber($A1)

    in cell B1 (note the $ sign to freeze the column letter) and copy it across for as many columns as you think you might ever need your data split out into and then copy all those cells down to the bottom of your data.

    HOW TO INSTALL UDFs
    ------------------------------------
    If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use NameOfTheUDF just like it was a built-in Excel function. See the example formula and instructions above.
    Last edited by Rick Rothstein; 05-21-2013 at 01:24 AM.

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Works great Thanks for the input Rothstein, much appreciated
    Last edited by Admin; 05-22-2013 at 03:30 PM. Reason: removed quote

Similar Threads

  1. Extract Number From Alphanumeric Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 10
    Last Post: 09-11-2013, 10:14 PM
  2. Replies: 6
    Last Post: 06-01-2013, 03:24 PM
  3. Extracting Numeric Values From Alphanumeric Text
    By Safal Shrestha in forum Excel Help
    Replies: 3
    Last Post: 03-21-2013, 12:04 PM
  4. Find a text substring that matches a given "pattern"
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 2
    Last Post: 02-10-2013, 06:19 AM
  5. Extract numbers from alphanumeric values
    By tushar.tarafdar in forum Excel Help
    Replies: 3
    Last Post: 09-20-2012, 10:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •