Generating a combination matrix

philobr

Active Member
Joined
Oct 17, 2005
Messages
280
Hi guys,
I need to create a matrix of all possible combinations from lists of data in columns
and put into rows.
I thought about trying to use CONCATENATE and Copy/PasteTranspose and recording
copy/paste macros but its not getting what I want.
From the example below I should get 60 rows:
List1*List2*List3
3*5*4 = 60 possible combinations.
Though the list I have could generate 27000 rows so I dont want to do this manually and I know this is probably simple to a lot of you guys so if you can help it would be greatly appreciated.

Example:
List1 List2 List3
A 1 u
B 2 v
C 3 w
4 x
5

Would become..........etc etc etc
Row1 A 1 u
Row2 A 1 v
Row3 A 1 w
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
or :-

[\*Code]
Dim x As Long
Dim y As Long
Dim z As Long

Dim x_c As Long
Dim y_c As Long
Dim z_c As Long

Dim No_of_Rows As Long
Dim Current_Row As Long

Current_Row = 1

x = Sheets("Sheet2").Range("A1").End(xlDown).Row
y = Sheets("Sheet2").Range("B1").End(xlDown).Row
z = Sheets("Sheet2").Range("C1").End(xlDown).Row

MsgBox x & y & z
x_c = 1
y_c = 1
z_c = 1


No_of_Rows = x * y * z

MsgBox No_of_Rows

'First Column

Do

Sheets("Sheet1").Cells(Current_Row, 1).Value = Sheets("Sheet2").Cells(x_c, 1).Value
Sheets("Sheet1").Cells(Current_Row, 2).Value = Sheets("Sheet2").Cells(y_c, 2).Value
Sheets("Sheet1").Cells(Current_Row, 3).Value = Sheets("Sheet2").Cells(z_c, 3).Value


MsgBox x_c & y_c & z_c

x_c = x_c + 1
y_c = y_c + 1
z_c = z_c + 1

If x_c > x Then
x_c = 1
End If

If y_c > y Then
y_c = 1
End If

If z_c > z Then
z_c = 1
End If

Current_Row = Current_Row + 1

Loop Until Current_Row > No_of_Rows



End Sub

[\Code]
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,794
Members
449,468
Latest member
AGreen17

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