PC Review


Reply
Thread Tools Rate Thread

compare name in cells

 
 
Dan
Guest
Posts: n/a
 
      26th Aug 2009
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

 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Aug 2009
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


"Dan" wrote:

> 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
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Aug 2009
change this

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

to

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



"Dan" wrote:

> 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
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Aug 2009
oops. replied to wrong mail.sorry

"Patrick Molloy" wrote:

> change this
>
> Set rng = Intersect(Target, Range("E:E"))
>
> to
>
> Set rng = Intersect(Target, Range("E:E;H:Q"))
>
>
>
> "Dan" wrote:
>
> > 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
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare 1 cell to column of cells returning adjacent cells info? Mr. Fine Microsoft Excel Worksheet Functions 1 15th Apr 2010 07:36 PM
Compare 4 cells John Microsoft Access 1 10th Jul 2008 02:09 PM
How do I compare cells and if FALSE compare to next cell in EXCEL =?Utf-8?B?Q2luZGll?= Microsoft Excel Worksheet Functions 0 24th Mar 2006 05:29 PM
Compare two cells from reference cells =?Utf-8?B?TWlrZSBL?= Microsoft Excel Worksheet Functions 2 26th Nov 2005 02:07 PM
Compare 2 cells in 2 worksheets, rewrite one of the cells dbomb Microsoft Excel Programming 1 28th Sep 2004 09:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:37 PM.