Finding possible combinations

Niels1994

New Member
Joined
Jun 23, 2016
Messages
4
Hello all,

I'm having this problem with our company's products and what combinations are possible.
The following is the situation:

CUSTOMER_IDPRODUCT_ID
1A
1B
1C
1D
2B
2C
3A
3B
3E
3F
3G

<tbody>
</tbody>

I have specified for each customer what products they have bought. And now I want to generate all possible product-combinations for each customer.

So, my output would be like this:
CUSTOMER_IDPOSSIBLE_COMBINATIONS
1A-B, A-C, A-D, B-C, B-D, C-D
2B-C
3A-B, A-E, A-F, A-G, B-E, B-F, B-G, E-F, E-G, F-G

<tbody>
</tbody>

How can I do this in Excel?
Can this be done by using regular formulas/functions, or do I need VBA for this? (in case I need VBA, any suggestions how to start?)


Thank you very much!
~ Niels
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I found a solution that solves it more or less.

Code:
Sub Combinations()


    Dim customerID As Integer
    Dim combinatiom As String
    Dim i, j As Integer
    Dim r1 As Range
    Dim sameProduct, sameCustomer As Boolean
    
    sameProduct = True
    i = 2
    For Each r1 In Range("A2", "A25")
        sameCustomer = True
                j = 1
                Do While sameCustomer
                    combination = ""
                    If r1.Offset(j, 0) = r1.Value Then
                        combination = r1.Offset(0, 1).Value + "-" + r1.Offset(j, 1).Value
                        j = j + 1
                        r1.Offset(0, i).Value = combination
                        i = i + 1
                    Else
                        sameCustomer = False
                        i = 2
                    End If
                Loop
    Next r1
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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