Inner and outer loops

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
Let's say I have two arrays with 4 of the same members. The members are A B C E. Now let's say I want to loop through both arrays to see if there is a match. To do that I had to do the following:


For i = 1 to ubound(1st_array)
For j = 1 to ubound(2nd_array)
if 1st_array(i) = 2nd_array(j) then
goto Z
end if
next
next

Now if there is no match, it seems that Excel will redundantly check certain combinations twice. For example, we only need check the following combinations

AB
AC
AD
AE

BC
BD
BE

CD
CE

But given the way that the function is set up, Excel will check some members more than once. It will also check

BA
CB
CA
DA
DB
DC

And it need not check those. This is not a big problem when we are dealing with arrays of 4 members but it is a problem when we are dealing with an array of 20 members. How do I get around this problem?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
With arrays, those combinations are all treated as unique, even though they are made up of the same combinations of letters. Because the order of the letters is different, they are unique to the others.
 
Upvote 0

Forum statistics

Threads
1,224,416
Messages
6,178,513
Members
452,853
Latest member
philipnjk64

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top