+ Reply to Thread
Results 1 to 10 of 10

Find and highlight similar cells in a column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-29-2008
    Location
    usa
    MS-Off Ver
    EXCEL 2010
    Posts
    116

    Find and highlight similar cells in a column

    is there a way to find similar cells within a column
    So i have a list of names some of them has middle name some of don't
    So the common denominator between two cell will be to match a least two words out the cell in order to be a match and it must be in the same column
    I don't know if this is possible to do
    Thank you for any help

    like this
    Martinez L Pedro
    Martinez Pedro
    Pedro Martinez lopez
    Pedro Martinez l
    Pedro Martinez
    Last edited by martinez_pedro; 05-12-2011 at 10:03 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Find and highlight similar cells in a column

    Hello Pedro,

    Do you have an actual name list that you can post?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    09-29-2008
    Location
    usa
    MS-Off Ver
    EXCEL 2010
    Posts
    116

    Re: Find and highlight similar cells in a column

    Here is the file with some sample names Thanks Leith Ross
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Find and highlight similar cells in a column

    Hello Pedro,

    Thank you for posting the workbook. What do you want to do once a possible match has been found?

  5. #5
    Forum Contributor
    Join Date
    09-29-2008
    Location
    usa
    MS-Off Ver
    EXCEL 2010
    Posts
    116

    Re: Find and highlight similar cells in a column

    I would like to group the possible match this way it will be easier to see the finding
    Thanks

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Find and highlight similar cells in a column

    Hello Pedro,

    Can you give me an example of what a grouping would like?

  7. #7
    Forum Contributor
    Join Date
    09-29-2008
    Location
    usa
    MS-Off Ver
    EXCEL 2010
    Posts
    116

    Re: Find and highlight similar cells in a column

    i attach a workbook so you can see what i mean by grouping the possible match together
    Attached Files Attached Files

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Find and highlight similar cells in a column

    Hello Pedro,

    That answers my question perfectly. Thank you. Now to start coding.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Find and highlight similar cells in a column

    Hello Pedro,

    This macro will place the groups on the active worksheet starting in cell "E2". There is button on the sheet to run the macro. Each group is separated by a blank line.
    Option Explicit
    
    Sub GroupNames()
    
      Dim Cell As Range
      Dim Dict As Object
      Dim I As Long
      Dim Key As Variant
      Dim NameList As Variant
      Dim R As Long
      Dim RegExp As Object
      Dim Rng As Range
      Dim RngEnd As Range
      Dim Text As String
      Dim Wks As Worksheet
      
        Set Wks = ActiveSheet
        
        Set Rng = Wks.Range("A2")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
        
        Set Dict = CreateObject("Scripting.Dictionary")
        Dict.CompareMode = vbTextCompare
        
        Set RegExp = CreateObject("VBScript.RegExp")
        RegExp.IgnoreCase = True
        RegExp.Pattern = "(\w+)(?:\s|\,\s)(\w+)(\s*.*)"
        
        
          For Each Cell In Rng
            Text = Trim(Cell.Value)
            If Text <> "" Then
               I = InStr(1, Text, ",")
               If I > 0 Then
                  Key = RegExp.Replace(Text, "$2 $1")
               Else
                  Key = RegExp.Replace(Text, "$1 $2")
               End If
               
               If Not Dict.Exists(Key) Then
                  Dict.Add Key, Text
               Else
                  Dict(Key) = Dict(Key) & "|" & Text
               End If
            End If
          Next Cell
          
        For Each Key In Dict.Keys
          NameList = Split(Dict(Key), "|")
          Wks.Range("E2").Offset(R, 0).Resize(UBound(NameList) + 1, 1) = WorksheetFunction.Transpose(NameList)
          R = R + UBound(NameList) + 2
        Next Key
        
    End Sub
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    09-29-2008
    Location
    usa
    MS-Off Ver
    EXCEL 2010
    Posts
    116

    Re: Find and highlight similar cells in a column

    Thank Leith Ross it works really perfecly
    Now if can just have your brain to be able to write macros like you I would be all set LOL
    Thanks Again

+ Reply to Thread

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