# Finding possible combinations

#### Niels1994

##### New Member
Hello all,

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

 CUSTOMER_ID PRODUCT_ID 1 A 1 B 1 C 1 D 2 B 2 C 3 A 3 B 3 E 3 F 3 G

<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_ID POSSIBLE_COMBINATIONS 1 A-B, A-C, A-D, B-C, B-D, C-D 2 B-C 3 A-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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

#### Niels1994

##### New Member
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``````

Replies
2
Views
71
Replies
3
Views
109
Replies
1
Views
161
Replies
2
Views
57
Replies
3
Views
169

1,128,180
Messages
5,629,188
Members
416,370
Latest member
Lgathana

### 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?

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