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

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
358
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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