Results 1 to 35 of 35

Compare Two Cells & Return Whats Common Between the two strings and delete the variation

Threaded View

  1. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Compare Two Cells & Return Whats Common Between the two strings and delete the variati

    OK
    try this one
    Function GetMaxCommon(ByVal txt As String, rng As Range _
        , myGroup As Long, CSense As Boolean) As String
        Dim r As Range, temp As String, m As Object
        Dim flg As Boolean, myPtn As String
        Static RegX As Object
        If RegX Is Nothing Then
            Set RegX = CreateObject("VBScript.RegExp")
            RegX.Global = True
            RegX.IgnoreCase = Not CSense
        End If
        With RegX
            .Pattern = "([\^\|\\\$\(\)\-\+\*\?\[\]\.])"
            txt = .Replace(txt, "\$1")
            myPtn = Join$(Split(txt), "|")
            For Each r In rng.Columns(1).Cells
                If flg Then Exit For
                If (r.Value <> txt) * (r(, 2).Value = myGroup) Then
                    temp = r.Value
                    With RegX
                        .Pattern = "(" & myPtn & ")"
                        If .test(temp) Then
                            GetMaxCommon = ""
                            For Each m In .Execute(temp)
                                GetMaxCommon = Trim$(GetMaxCommon & _
                                " " & m.submatches(0))
                            Next
                            .Pattern = "([\^\|\\\$\(\)\-\+\*\?\[\]\.])"
                            myPtn = Replace(.Replace(GetMaxCommon, "\$1"), " ", "|")
                        Else
                            GetMaxCommon = ""
                            flg = True
                            Exit For
                        End If
                    End With
                End If
            Next
        End With
    End Function
    Last edited by jindon; 04-18-2012 at 12:53 AM.

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