# Combinations in Calc (was "Permutations in Calc" )

Hello, is it possible to create ~~permutations~~ combinations in Calc? It is the same thing answered here for Excel.

What I have in the document:

```
A B
Abc 12:34
Def 56:78
Ghi 90:12
Jkl 34:56
...
```

What I want to achieve with those values:

```
C D E F
Abc 12:34 Def 56:78
Abc 12:34 Ghi 90:12
Abc 12:34 Jkl 34:56
Def 56:78 Ghi 90:12
Def 56:78 Jkl 34:56
Ghi 90:12 Jkl 34:56
...
```

Edit @karolus: its about **Combinations** (of 2) but not **Permutations** /edit

Explanation:

Columns A and B can contain any combination of text and numbers (if that is important at all), this example only displays the most common structure. It should create combinations only for rows on the way down, i. e. "Abc...Def..." is enough, there shouldn't be "Def...Abc...".

Here is the solution for Excel (credits to John):

```
Sub CreatePermutation()
Dim FirstCell As Integer
Dim SecondCell As Integer
Dim NumRows As Integer
Dim OutputRow As Long
' Get the total number of rows in column A
NumRows = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row()
' You want to start outputting in row 1
OutputRow = 1
For FirstCell = 1 To NumRows - 1
For SecondCell = FirstCell + 1 To NumRows
' Put in the data from the first cell into columnc C & D
Cells(OutputRow, 3).Value = Cells(FirstCell, 1).Value
Cells(OutputRow, 4).Value = Cells(FirstCell, 2).Value
' Put in the data from the second cell into column E & F
Cells(OutputRow, 5).Value = Cells(SecondCell, 1).Value
Cells(OutputRow, 6).Value = Cells(SecondCell, 2).Value
' Move to the next row to output
OutputRow = OutputRow + 1
Next SecondCell
Next FirstCell
End Sub
```

Is it possible to translate this macro to Calc or some other way to perform this task?