Here's the approach I took:Since I don't know how many unique words you'll have 
in a given cell,and I don't know if they will always be separated by a comma,I 
replaced the comma with a space, then used a space as a word delimiter.
Now, if you actually are looking for PHRASES, and each PHRASE is separated by a 
comma, then you'll want to change the split() function to:strArray = 
Split(Cells(2, C).Value, ",")
Otherwise:
The technique I used was to create a Dictionary object and populate it with the 
unique phrases or words from row 2.then, check each word/phrase from row 3 to 
see if it is in the dictionary.
Option ExplicitSub Find_Matches()
    Dim nCols, C
    Dim strArray, inx
    Dim Dict_Data
    Dim DupCnt
    Dim Val As String
    
    Set Dict_Data = CreateObject("Scripting.Dictionary")
    
    nCols = Application.WorksheetFunction.CountA(Range("1:1"))
    ActiveSheet.Range("4:4").ClearContents
    For C = 1 To nCols
        If ((Cells(2, C).Value & "X" <> "X") _
        And (Cells(3, C).Value & "X" <> "X")) Then
            Dict_Data.RemoveAll
            '--------------------------
            ' Load Dictionary item
            '--------------------------
            strArray = Split(Replace(Cells(2, C).Value, ",", " "), " ")
            For inx = 0 To UBound(strArray)
                Val = UCase(strArray(inx))
                If (Val & "X" <> "X") Then
                    If (Not Dict_Data.exists(Val)) Then
                            Dict_Data.Add Val, C
                    End If
                End If
            Next inx
            '-----------------------
            ' Check for duplicates
            '-----------------------
            DupCnt = 0
            strArray = Split(Replace(Cells(3, C).Value, ",", " "), " ")
            For inx = 0 To UBound(strArray)
                Val = UCase(strArray(inx))
                If (Val & "X" <> "X") Then
                    If (Dict_Data.exists(Val)) Then
                        DupCnt = DupCnt + 1
                    End If
                End If
            Next inx
            Cells(4, C).Value = DupCnt
        End If
    Next C
End Sub
 Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------
 
      From: Kathryn S <evergreen.s1...@gmail.com>
 To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> 
 Sent: Monday, August 10, 2015 1:53 PM
 Subject: $$Excel-Macros$$ count # of common strings between two cells
   
Here is what I have --

 
| 1 | A | B | C | D | E | F | G |
| 2 | 12,13 | 11 | 9,10 | 12 | 14,16 | 6 | A,B |
| 3 | 12 | 11 | 9,10 | 11 | 18 | 6 | A |



1. I would like to find number of common string between A2 and A3, B2 and B3, 
etc

2. I would like to get total number of strings in each line, regardless of cell 
or comma

3. this is what the results like

 
|  
| 1 | A | B | C | D | E | F | G | # strings |
| 2 | 12,13 | 11 | 9,10 | 12 | 14,16 | 6 | A,B | 11 |
| 3 | 12 | 11 | 9,10 | 11 | 18 | 6 | A | 8 |
| # in Common | 1 | 1 | 2 | 0 | 0 | 1 | 1 | 
 |


Can anyone provide any hints? Thanks a lot!
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |


 
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |


 
|  
|  
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |

 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 |

 | 
 | 
 | 
 | 
 | 
 | 
 |
| 
 | 
 | 
 | 
 | 
 | 
 | 
 |


-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


   

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to