Distinct X,Y Data Combinations

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
358
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:-[TABLE="width: 248"]
<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>[TR]
[TD="class: xl63, width: 90, bgcolor: transparent"]Rows in Data[/TD]
[TD="class: xl63, width: 125, bgcolor: transparent"]No Permutations[/TD]
[TD="class: xl63, width: 114, bgcolor: transparent"]Sheet Rows Used[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]8[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]40320[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]322560[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]9[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]362880[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]2903040[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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