how do I show all variables from 3 columns?

turtle37

New Member
Joined
Sep 5, 2006
Messages
2
not sure how to word this one, but I have 3 columns with approx 12 different words in one column, 3 in the next, 40 in the next.
What do I need to do to display all variables/combinations which are possible???
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi, welcome to the Board!

This assumes a couple of things:

1. Your lists are in columns A:C, starting in Row1
2. You want to output the result starting in column F
3. You won't end up with over 65536 combinations

Place the following code in a new module (Alt + F11, Insert > Module, paste the code, Alt + Q to return to Excel).
To run the code, Alt + F8 and double-click the macro name

Code:
Sub AllCombos()
    Dim nCount1 As Integer
    Dim nCount2 As Integer
    Dim nCount3 As Integer
    Dim x As Long, m As Long
    Dim i As Integer, j As Integer, k As Integer
    
    Dim vArray() As Variant
    
    nCount1 = Cells(65536, 1).End(xlUp).Row
    nCount2 = Cells(65536, 2).End(xlUp).Row
    nCount3 = Cells(65536, 3).End(xlUp).Row
    x = nCount1 * nCount2 * nCount3
    
    ReDim vArray(1 To x, 1 To 3)
    m = 1
    For i = 1 To nCount1
        For j = 1 To nCount2
            For k = 1 To nCount3
                vArray(m, 1) = Cells(i, 1)
                vArray(m, 2) = Cells(j, 2)
                vArray(m, 3) = Cells(k, 3)
                m = m + 1
            Next k
        Next j
    Next i

    Range("F1").Resize(x, 3) = vArray
End Sub
Denis
 
Upvote 0

Forum statistics

Threads
1,217,255
Messages
6,135,496
Members
449,943
Latest member
thsix

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