Results 1 to 7 of 7

Searching for a String with Pattern

Threaded View

  1. #1
    Registered User
    Join Date
    01-12-2004
    Location
    NY
    Posts
    92

    Searching for a String with Pattern

    I posted this thread in the Excel area, then I realized that I can do this much easier in Access.

    I need help creating a VB function.

    I have a column with text (not exceeding 255 chars). Within the text, there is a specific 8 character string I'm interested in pulling (2 letters, 5 numbers, 1 letter) <= this is always the pattern (i.e. AB12345C).

    The function needs to search through the text and when it finds the first instance return the string. If the function does not find any string, then it should return nothing.

    Any help is greatly appreciated

    This is a sample of the data I have in the column of my table

    Notes
    12342 John Doe AB12345C EN ME
    897342 Jane Doe DE54321F EN ME
    8923 Peter Doe GH23456I EN ME
    40293074 Jamie Doe JK34567L EN ME
    2093 Frank Doe MN45678O EN ME 298730 Alex Doe PQ98765R EN ME

    This is the VB function I want to modify to include the specific pattern [A-Z]{2}[0-9]{5}[A-Z]{1}

    I know I have to change the following argument to accomodate my string, but I don't know how:

    IsNumeric(varString(intCounter))
    Public Function fExtractECodes(strString As String)
    
    Dim varString As Variant
    Dim intCounter As Integer
    Dim strBuild As String
    Dim intNumOfMatches As Integer
    
        varString = Split(strString, " ")
    
    For intCounter = LBound(varString) To UBound(varString)
    
        If Len(varString(intCounter)) = 8 And IsNumeric(varString(intCounter)) Then
        intNumOfMatches = intNumOfMatches + 1
        strBuild = strBuild & " " & varString(intCounter)
    
    End If
    
    Next
    
        If intNumOfMatches = 1 Then
        fExtractECodes = Trim(strBuild)
    
    Else
    
        fExtractECodes = Null
    
    End If
    
    End Function
    Last edited by nrage21; 11-18-2010 at 09:44 PM.
    _________________
    Regards,
    nrage21

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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