Distinct X,Y Data Combinations

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
I am posting this in lieu of an unanswered thread -- "VBA to List all Possible Pairs of X,Y Data in two Columns"
HTML:
https://www.mrexcel.com/forum/excel-questions/1038311-vba-list-all-possible-pairs-x-y-data-two-columns.html

I have two columns of X,Y data. I need to rearrange them so that I get all possible distinct pairs. That is,

Keep the X’s in the same order. There are 5 possible Y’s for the first position. For each of these, there are 4 possible Y’s for the second. For each of these there are 3 possible Y’s for the third, and 2 for the fourth. And, so on.

Once we are done with the first value of X, we go on to the next, and so on.

For Example,
The master pair data is:

X,Y
1,6
2,7
3,8
4,9
5,0

The first few distinct possibilities (of the 120 possible) done manually are:

1,7
2,8
3,9
4,0
5,6

1,8
2,9
3,0
4,6
5,7

and so on.

I want a VBA solution to this and handle X,Y data with more than 5 pairs.

The number of ways the X and Y numbers could be paired involves pairing change only (Note that X’s do not become Y’s and Y’s do not become X’s. It is the pairings that change). This gives N=5, thus FACT(5) = 120 possible X,Y data with pair changes. If N the FACT(N) possible X,Y data pairs possible.
 
In the "Permutation" code change
Code:
p = 5

'To 

p = rRng.Count

NB:-
Rows in DataNo PermutationsSheet Rows Used
840320322560
93628802903040
<colgroup><col width="90" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3214;"> <col width="125" style="width: 94pt; mso-width-source: userset; mso-width-alt: 4437;"> <col width="114" style="width: 86pt; mso-width-source: userset; mso-width-alt: 4067;"> <tbody> </tbody>
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,393
Messages
6,124,680
Members
449,180
Latest member
kfhw720

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