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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,214,787
Messages
6,121,569
Members
449,038
Latest member
Guest1337

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