PC Review


Reply
Thread Tools Rate Thread

Comparing lists in Excel/Visual Basic

 
 
ErwinAlonzo@gmail.com
Guest
Posts: n/a
 
      12th Apr 2008
Let me set up the problem. I have two columns of data (names of
people) in Excel. I need to see if the names in Column A are the same
in Column B. However, the catch is that the order of the names in both
columns can be different. Also, the maximum number of names in each
column is 10, but there is no minimum, therefore the two lists may
have a different number of names.

The ultimate goal of this exercise is to see whether the names in
Column A and B are exactly the same (the order doesn't matter) and
obtain a simple TRUE or FALSE result.

I've been testing various IF statements (using a For...Next loop to go
down the list) but have had no luck. If anyone can help me understand
the logic to go about solving this, I would really appreciate it.
Thanks.
 
Reply With Quote
 
 
 
 
David McRitchie
Guest
Posts: n/a
 
      12th Apr 2008
Rather than True or False, if you used actual numbers
you might also spot some duplicates

C2: =IF(ISBLANK(A2),"",COUNTIF(B:B,A2))
D2: =IF(ISBLANK(B2),"",COUNTIF(A:A,B2))

But if you want true or false then
C2: =IF(ISBLANK(A2),"",COUNTIF(B:B,A2)>0)
D2: =IF(ISBLANK(B2),"",COUNTIF(A:A,B2)>0)

use the fill handle to fill down
http://www.mvps.org/dmcritchie/excel/fillhand.htm
--
HTH,
David McRitchie, Microsoft MVP -- Excel
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm


<(E-Mail Removed)> wrote in message news:34241a6f-e2be-45c5-9df3-(E-Mail Removed)...
> Let me set up the problem. I have two columns of data (names of
> people) in Excel. I need to see if the names in Column A are the same
> in Column B. However, the catch is that the order of the names in both
> columns can be different. Also, the maximum number of names in each
> column is 10, but there is no minimum, therefore the two lists may
> have a different number of names.
>
> The ultimate goal of this exercise is to see whether the names in
> Column A and B are exactly the same (the order doesn't matter) and
> obtain a simple TRUE or FALSE result.
>
> I've been testing various IF statements (using a For...Next loop to go
> down the list) but have had no luck. If anyone can help me understand
> the logic to go about solving this, I would really appreciate it.
> Thanks.

 
Reply With Quote
 
Mike Williams
Guest
Posts: n/a
 
      12th Apr 2008
On 12 Apr, 03:55, ErwinAlo...@gmail.com wrote:

> . . . the order of the names in both columns
> can be different. Also, the maximum number
> of names in each column is 10, but there is
> no minimum, therefore the two lists may have
> a different number of names. The ultimate
> goal of this exercise is to see whether the
> names in Column A and B are exactly the same
> the order doesn't matter) . . .


You can write various algorithms for this one, but a very easy method
would be to use a simple "stock" algorithm that you probably already
have to hand, a sorting algorithm. Firstly run through the Excel data
and load the names exactly as they appear in the two Excel columns
into two separate VB String arrays. If the two arrays do not then
contain the same number of strings then straight away you can return a
false, since the list cannot possibly contain exactly the same set of
names. Then, if both arrays do contain the same number of strings,
perform a simple Sort (seperately) on both arrays. The names in the
two arrays will now be in sorted alphabetical order and you can then
simply run through them just once one element at a time conparing
element (n) of the first array with element (n) of the second array.
If you get to the end of the list without finding a "mismatch" on any
element then both arrays are the same. You would probably want to use
a textual comparison, both when yuo perform the sort and when you run
through the elements, so that Bill Gates for example would be seen as
being the same as bill gates.

Mike

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      12th Apr 2008
Another one, just this single formula:

=SUMPRODUCT(--(COUNTIF(A1:A10,B1:B10)<>1))=0

Note this is not case sensitive.

Regards,
Peter T

<(E-Mail Removed)> wrote in message
news:34241a6f-e2be-45c5-9df3-(E-Mail Removed)...
> Let me set up the problem. I have two columns of data (names of
> people) in Excel. I need to see if the names in Column A are the same
> in Column B. However, the catch is that the order of the names in both
> columns can be different. Also, the maximum number of names in each
> column is 10, but there is no minimum, therefore the two lists may
> have a different number of names.
>
> The ultimate goal of this exercise is to see whether the names in
> Column A and B are exactly the same (the order doesn't matter) and
> obtain a simple TRUE or FALSE result.
>
> I've been testing various IF statements (using a For...Next loop to go
> down the list) but have had no luck. If anyone can help me understand
> the logic to go about solving this, I would really appreciate it.
> Thanks.



 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      12th Apr 2008
Scrub previous! Could give false +ve if there are duplicates in column B.

Try this one instead -

=SUMPRODUCT(--(COUNTIF(A1:A10,B1:B10)<>COUNTIF(B1:B10,B1:B10))) = 0

Regards,
Peter T

"Peter T" <peter_t@discussions> wrote in message
news:e48F%(E-Mail Removed)...
> Another one, just this single formula:
>
> =SUMPRODUCT(--(COUNTIF(A1:A10,B1:B10)<>1))=0
>
> Note this is not case sensitive.
>
> Regards,
> Peter T
>
> <(E-Mail Removed)> wrote in message
> news:34241a6f-e2be-45c5-9df3-(E-Mail Removed)...
> > Let me set up the problem. I have two columns of data (names of
> > people) in Excel. I need to see if the names in Column A are the same
> > in Column B. However, the catch is that the order of the names in both
> > columns can be different. Also, the maximum number of names in each
> > column is 10, but there is no minimum, therefore the two lists may
> > have a different number of names.
> >
> > The ultimate goal of this exercise is to see whether the names in
> > Column A and B are exactly the same (the order doesn't matter) and
> > obtain a simple TRUE or FALSE result.
> >
> > I've been testing various IF statements (using a For...Next loop to go
> > down the list) but have had no luck. If anyone can help me understand
> > the logic to go about solving this, I would really appreciate it.
> > Thanks.

>
>



 
Reply With Quote
 
Martin Trump
Guest
Posts: n/a
 
      12th Apr 2008
In message
<8dac8876-dfdb-4841-b0e2-(E-Mail Removed)>, Mike
Williams <(E-Mail Removed)> writes
>Then, if both arrays do contain the same number of strings, perform a
>simple Sort (seperately) on both arrays. The names in the two arrays
>will now be in sorted


How about two ListBoxes with Sorted = True ?

Regards
--
Martin Trump
 
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
Lists in Visual Basic - Excel bg_ie@yahoo.com Microsoft Excel Programming 1 11th Jun 2007 06:53 PM
Can I run Visual Basic procedure using Excel Visual Basic editor? =?Utf-8?B?am9obi5qYWNvYnM3MQ==?= Microsoft Excel Programming 3 26th Dec 2005 02:22 PM
Comparing two lists in Excel Jimmy Joseph Microsoft Excel Discussion 2 13th Oct 2005 05:02 AM
Creating address list personal distribution lists with visual basic Ed Microsoft Outlook VBA Programming 1 31st Oct 2003 05:01 AM
Comparing 2 lists in Excel Todd Microsoft Excel Worksheet Functions 2 21st Oct 2003 04:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:12 AM.