VBA to List all Possible Pairs of X,Y Data in two Columns

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
I have the following X,Y Data in two Columns:

X=4,8,2,1,9 (Column A)
Y=3,5,1,7,8 (Column B)

What I need is, on the subsequent rows, all the possible rearrangements of this data.

That is, for example:

1st output:
X=4,8,2,1,9 (Column A)
Y=5,1,7,8,3 (Column B)

2nd output:
X=4,8,2,1,9 (Column A)
Y=1,7,8,3,5 (Column B)

and so on.

In the example the values were changing their position in Y only. But, in reality there are 120 such possible pairs for N=5 X,Y Data, i.e. FACT(5)=120 (Factorial).

I need to list all possible pairs of N-pair x,y datasets (N can change).

Is there a way to get these pairs using VBA?

Thanks.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
To simply,

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.

But, if the Xs and Ys can interchange, with N=10 (n1=5, n2=5), this gives =FACT(10)/(FACT(5)*FACT(5)) = 252 possible X,Y data with X,Y changes as well as pair changes.
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,658
Members
449,177
Latest member
Sousanna Aristiadou

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