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
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    14
    or ?

    Code:
    Function snb_002(c00)
        snb_002 = Join(Filter(Split(Join(Filter(Split(c00, "."), "0"), "")), "0"))
    End Function
    Last edited by Rick Rothstein; 05-21-2013 at 02:27 AM.

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by snb View Post
    or ?

    Code:
    Function snb_002(c00)
        snb_002 = Join(Filter(Split(Join(Filter(Split(c00, "."), "0"), "")), "0"))
    End Function
    Interesting... it never occurred to me that the OP might have wanted the returned value in the same cell (which I'm guessing he didn't given his response to my posting), however, that is a perfectly reasonable reading of the original posting. I don't know if you want to try to fix it or not (given the OP's response to my posting), but your output is incorrect for the 2nd sample data string....

    CABLE AND WIRELESSINV. 2000680771USA

    as it retains the USA which the OP showed as not desired in his example output. It is not clear if the other date format (the one that starts with three letters) could have unwanted attached letters on the end of it or not, so if you try to post a fix (for the record), you might want to assume yes and design your fix around it as well.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    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

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    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.

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
  •