Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Compare two arrays in VBA to find dupes

I have two simple array variables in some VBA code. I'm wondering
what is the simplest way to compare the contents (typically less than
50 items in each array) to find dupes. Specifically, I would do this:

If arFirstList (i) is in arSecondList then
Do this stuff....
Else
Do this other stuff
End if

Is there a function that would handle this or do I need to create a
For Next loop that completely cycles through the arSecondList each
time I go to a new member in arFirstList?

Thanks in advance.

- John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Compare two arrays in VBA to find dupes

If we make a concatenated version of the second list:

t = aSecondList(0)
For i = 1 To UBound(aSecondList)
t = t & "!" & aSecondList(i)
Next

Then all we have to do is check each value in the first list against t using
InStr()
--
Gary's Student
gsnu200704


"John Michl" wrote:

I have two simple array variables in some VBA code. I'm wondering
what is the simplest way to compare the contents (typically less than
50 items in each array) to find dupes. Specifically, I would do this:

If arFirstList (i) is in arSecondList then
Do this stuff....
Else
Do this other stuff
End if

Is there a function that would handle this or do I need to create a
For Next loop that completely cycles through the arSecondList each
time I go to a new member in arFirstList?

Thanks in advance.

- John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Compare two arrays in VBA to find dupes

Dim i as Long, res as Variant
for i = lbound(arFirstList) to Ubound(arFirstList)
res = application.Match(arFirstList(i),arSecondList,0)
if not iserror(res) then
do this stuff
else
do this other stuff
end if
Next

--
Regards,
Tom Ogilvy



"John Michl" wrote:

I have two simple array variables in some VBA code. I'm wondering
what is the simplest way to compare the contents (typically less than
50 items in each array) to find dupes. Specifically, I would do this:

If arFirstList (i) is in arSecondList then
Do this stuff....
Else
Do this other stuff
End if

Is there a function that would handle this or do I need to create a
For Next loop that completely cycles through the arSecondList each
time I go to a new member in arFirstList?

Thanks in advance.

- John


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate Find not finding all dupes Father John Excel Discussion (Misc queries) 3 March 14th 10 03:29 PM
Compare arrays mavxob Excel Worksheet Functions 5 March 6th 08 10:55 PM
Compare arrays youngster Excel Worksheet Functions 3 July 31st 07 04:36 PM
how to compare two arrays? Ofer Excel Programming 1 December 7th 06 07:10 PM
How can I compare 2 sets of Social Security #'s and Identify dupes vwwolfe Excel Discussion (Misc queries) 1 February 3rd 05 10:08 PM


All times are GMT +1. The time now is 01:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"