compare name in cells

D

Dan

I have 2 cells that I need to compare
In each cell there are name of student separated by coma
so A1= Bill,Marco A2= Bill,John,Marco,Bella

How can I have the unmatching names (name in A2 but not in A1) in A3
So A3 should be John,Bella

Any idea?
Thanks
Dan
 
P

Patrick Molloy

try this User Defined Function:

Option Explicit

Function compare(text1 As String, text2 As String) As String
'find items in text2 that are not in text1
Dim vtext2 As Variant
Dim vtext1 As Variant
Dim res As String
Dim txt As String
Dim index1 As Long
Dim index2 As Long
Dim bFound As Boolean

vtext1 = Split(text1, ",")
vtext2 = Split(text2, ",")

For index2 = LBound(vtext2, 1) To UBound(vtext2, 1)
txt = ""
bFound = False
For index1 = LBound(vtext1, 1) To UBound(vtext1, 1)
If vtext1(index1) = vtext2(index2) Then
bFound = True
Exit For
End If
Next
If Not bFound Then
res = res & "," & vtext2(index2)
End If
Next

compare = Mid(res, 2)



End Function
 
P

Patrick Molloy

change this

Set rng = Intersect(Target, Range("E:E"))

to

Set rng = Intersect(Target, Range("E:E;H:Q"))
 
P

Patrick Molloy

oops. replied to wrong mail.sorry

Patrick Molloy said:
change this

Set rng = Intersect(Target, Range("E:E"))

to

Set rng = Intersect(Target, Range("E:E;H:Q"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top