Combine all possible combinations from single column without vba

andrew_milonavic

Board Regular
Joined
Nov 16, 2016
Messages
98
Hi Everyone,

I'd like to combine all possible combinations (text) from a single column into another.

I was able to find this formula
Code:
=IF(ROW()-ROW($F$1)+1>COUNTA(A:A)*COUNTA(B:B),"",INDEX(A:A,INT((ROW()-ROW($F$1))/COUNTA(B:B)+1))&INDEX(B:B,MOD(ROW()-ROW($F$1),COUNTA(B:B))+1))
which works perfectly for two columns of data but I wasn't able to make it work for just one column of data.

Hope you guys can help!

Thanks

Andrew
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hey Wideboydixon,

Thanks for the reply.

Lets say I've got 6 fruits (Apple, Orange, Grapefruit, Banana, Kiwi, Grapes) in column 1 (A1-A6). I'd like to excel to automatically combine all the possible combinations into column B. The data would then look like Apple orange, Apple grapefruit, apple banana etc etc.

The formula I posted does the possible combinations but needs to rows of data.

Make sense?

Thanks

Andrew
 
Upvote 0
Do you mean pick all possible pairs? Are you allowed to pick duplicates? {Apple, Apple}? Do you want to include triples also? {Apple, Orange, Grapefruit}. Quads?

WBD
 
Upvote 0
Tricky and reasonably complex.


Book1
AB
1AntelopeAntelope,Bear
2BearAntelope,Chicken
3ChickenAntelope,Dog
4DogAntelope,Elephant
5ElephantAntelope,Frog
6FrogBear,Antelope
7Bear,Chicken
8Bear,Dog
9Bear,Elephant
10Bear,Frog
11Chicken,Antelope
12Chicken,Bear
13Chicken,Dog
14Chicken,Elephant
15Chicken,Frog
16Dog,Antelope
17Dog,Bear
18Dog,Chicken
19Dog,Elephant
20Dog,Frog
21Elephant,Antelope
22Elephant,Bear
23Elephant,Chicken
24Elephant,Dog
25Elephant,Frog
26Frog,Antelope
27Frog,Bear
28Frog,Chicken
29Frog,Dog
30Frog,Elephant
Sheet1
Cell Formulas
RangeFormula
B1=IF(ROW()>COUNTA($A:$A)*(COUNTA($A:$A)-1),"",INDEX($A:$A,INT((ROW()-1)/(COUNTA($A:$A)-1))+1) & "," & INDEX($A:$A,MOD(ROW()-1,COUNTA($A:$A)-1)+1+IF(MOD(ROW()-1,COUNTA($A:$A)-1)>=INT((ROW()-1)/(COUNTA($A:$A)-1)),1,0)))


WBD
 
Upvote 0
Hey wideboydixon,

Is there a way to stop the formula from producing duplicates of the reverse order? Sticking with your example allowing "antelope, bear" but not "bear, antelope"??

Maybe that's what you were asking about previously, re duplicates, if so I appologize for not picking up on it.

Thanks

Andrew
 
Upvote 0
Trying to think about doing that in a formula gives me a headache. Trivial task for VBA though:

Code:
Public Sub GetUniquePairs()

Dim lastRow As Long
Dim thisRow As Long
Dim i As Long
Dim j As Long

lastRow = Cells(Rows.Count, 1).End(xlUp).Row
thisRow = 1
For i = 1 To lastRow - 1
    For j = i + 1 To lastRow
        Cells(thisRow, 2).Value = Cells(i, 1).Value & "," & Cells(j, 1).Value
        thisRow = thisRow + 1
    Next j
Next i

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,223,277
Messages
6,171,148
Members
452,382
Latest member
RonChand

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