Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

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

  1. #11
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by larkspur View Post
    very interesting.... thanks snb, however I'd need your function to return the following formats:
    1. 3 letters LBC,ABC,FXI etc followed by 5 numerics, a back slash then 2 numerics e.g. 12540/01
    2. 2000 followed by 6 numerics
    3. 1800 followed by 6 numerics
    If you are interested in having the output as a comma delimited string within a single cell, like 'snb' assumed you wanted, as opposed to the multi-cell output of my original UDF, you could use the following UDF (note I used the same function name, so you would have to comment out or delete my previous UDF from your module before running this one)...
    Code:
    Function InvoiceNumbers(S As String) As String
      Dim X As Long, OutText As String
      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
      If Len(S) Then InvoiceNumbers = Mid(OutText, 3)
    End Function
    Note... unlike my previous UDF, this one can be placed anywhere (that is, it does not have to be placed next to the cell it is processing). Also, the calling formula would be the same....

    =InvoiceNumbers(A1)
    Last edited by Rick Rothstein; 05-22-2013 at 01:07 AM.

  2. #12
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    @Rick

    You might have misinterpreted my suggestion: it's a UDF; so the result will be the 'filtered' value of another cell: no concatenation, no comma separation etc.

    Because I have no idea what the other items look like I can only suggest something for the items provided:

    Code:
    Function snb_002(c00)
        snb_002 = Join(Filter(Split(Join(Filter(Split(Replace(c00, "USA", ".USA"), "."), "0"), "")), "0"))
    End Function
    Attached Files Attached Files
    Last edited by snb; 05-22-2013 at 02:50 PM.

  3. #13
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by snb View Post
    @Rick

    You might have misinterpreted my suggestion: it's a UDF; so the result will be the 'filtered' value of another cell: no concatenation, no comma separation etc.

    Because I have no idea what the other items look like I can only suggest something for the items provided:

    Code:
    Function snb_002(c00)
        snb_002 = Join(Filter(Split(Join(Filter(Split(Replace(c00, "USA", ".USA"), "."), "0"), "")), "0"))
    End Function
    Yes, I did misinterpret your code (sorry for not trying it first)... I saw Filter and Join and thought your code was finding the desired "number" parts (no matter what, if anything, was between them) and joining (what I was referring to when I said "concatenating") them together. I see, now, that is not what your code is doing. I do not know if this was a typo on the OP's part or not, but the first data item...

    1.JET INTERNATIONALINV NO.ABC12539/01 ABC12540/01TCI12538/01

    has two of his "numbers" at the end with no separation between them. Your function preserves that combined pair of "numbers" whereas both of my coded functions separate them... I am guessing adding that functionality to your nicely compact UDF would be difficult to do?

  4. #14
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Well it's rather complicated to write concise code for inconsistent data, but in this case:

    Code:
    Function snb_002(c00)
        snb_002 = Join(Filter(Split(Replace(Replace(Replace(c00, "USA", " USA"), "TCI", " TCI"), ".", " . ")), "0"))
    End Function
    Last edited by snb; 05-23-2013 at 12:44 AM.

  5. #15
    Junior Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    book1.jpg

    Thanks again snb for your updated UDF, however this extraction is just the first part of what I'm working on. So Rick's original separated field entry works just fine

    Next step is to locate those individual numbers on another workbook, then return the corresponding ID number/s and value/s, which are in different cells back to individual cells on this workbook. As I'm new to macros would either of you be able to shed some light on the process (example image attached?)
    Last edited by larkspur; 05-25-2013 at 07:29 AM.

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
  •