Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have two relatively large 1D arrays (I could make them into a two D
with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
unless the arrays are sorted, I would think you would have to loop and
compare on each element. If they were on a worksheet, you could use the countif formula. -- Regards, Tom Ogilvy "Marston" wrote in message om... I have two relatively large 1D arrays (I could make them into a two D with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Marston wrote:
I have two relatively large 1D arrays (I could make them into a two D with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? What does "forever" mean? Approximately how long does it take? Alan Beban |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Marston wrote:
I have two relatively large 1D arrays (I could make them into a two D with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? And what version of Excel are you using? Alan Beban |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't know if this will be faster than looping through the 2nd array, but
you can try it: Dim Found As Variant For i = 1 to UBound(Array1) Found=(Application.Match(Array1(i),Array2,0)) If IsError(Found) Then 'not there Else 'a match End If Next i On 31 Aug 2004 07:34:32 -0700, (Marston) wrote: I have two relatively large 1D arrays (I could make them into a two D with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub Tester9()
Dim myarray(1 To 5462) For i = 1 To UBound(myarray) myarray(i) = i Next res = Application.Match(Int(Rnd() * UBound(myarray)), myarray, 0) If Not IsError(res) Then MsgBox res End If End Sub raises a type mismatch error. Match doesn't work with an array with more than 5461 elements, at least not in xl2000 and below. One reason I didn't suggest that. It may be more robust in Excel 2002/3. -- Regards, Tom Ogilvy "Myrna Larson" wrote in message ... I don't know if this will be faster than looping through the 2nd array, but you can try it: Dim Found As Variant For i = 1 to UBound(Array1) Found=(Application.Match(Array1(i),Array2,0)) If IsError(Found) Then 'not there Else 'a match End If Next i On 31 Aug 2004 07:34:32 -0700, (Marston) wrote: I have two relatively large 1D arrays (I could make them into a two D with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi, Tom:
I'm using XL 2002 (XP) and your code works fine there. I also tried it with an array Dim'd 1 to 33,000 and there no problems. It's nice to see that MS has actually fixed some bugs. Thanks for the caveat for XL97 and 2000 users. BTW, in some testing I did with either XL5 or 95, MATCH on a sorted array was slower than a binary search, but that changed in a later version. Myrna Larson On Tue, 31 Aug 2004 14:22:08 -0400, "Tom Ogilvy" wrote: Sub Tester9() Dim myarray(1 To 5462) For i = 1 To UBound(myarray) myarray(i) = i Next res = Application.Match(Int(Rnd() * UBound(myarray)), myarray, 0) If Not IsError(res) Then MsgBox res End If End Sub raises a type mismatch error. Match doesn't work with an array with more than 5461 elements, at least not in xl2000 and below. One reason I didn't suggest that. It may be more robust in Excel 2002/3. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
BTW, the fastest way to search is a binary search, but it requires that the
array being searched is sorted in ascending order. Is your data sorted? If not, can you sort it? I can give you routines for sorting and for a binary search if this approach is feasible. On 31 Aug 2004 07:34:32 -0700, (Marston) wrote: I have two relatively large 1D arrays (I could make them into a two D with a dummy column if that would help, but I can't imagine how). Both arrays contain a series of strings, with each string being exactly the same length (in this case 18 characters). The characters are numbers as strings. Each array contains 20,000-30,000 elements. The challenge is finding a fast way to compare each element in one array to see if it exists in the second array. I find that if I do this through any simple stepwise looping it takes forever. Any suggestions? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
comparing ranges/arrays | Excel Worksheet Functions | |||
Comparing 2 arrays | Excel Worksheet Functions | |||
Comparing Arrays | Excel Discussion (Misc queries) | |||
Comparing Arrays | Excel Worksheet Functions | |||
Comparing two arrays/ranges | Excel Programming |