How does one sort data into different columns?

I am using Calc on OS X, version 4.2.8.2.

I have a single column list like this with entries A, B, C, D, A, C. As a column, so that this is a 1 x 6 matrix. (Sorry… I don’t know how to display table here.)

I was wondering, how might I sort this into multiple columns, such that A is in the first column, B in the second, C third, D fourth, A first, and B second?

I could filter it and do it manually, cutting and pasting, but does anyone know a more direct way?

First select the range to sort.
Menu/Data/Sort
here you can select what columns to sort and how, and verify the options in options tab.

@mariosv

The Question is not about Sorting, @teraciv want to group a DataPattern from one Column-for Example

A
B
C
D
A
C

grouped into Rows of Equal Entrys:

A | A
B
C | C
D

Right @karolus.

And what is now the answer to the original question???

@ROSt53: You want an Answer ?

from itertools import groupby

def group_into_rows(*_):
    doc = XSCRIPTCONTEXT.getDocument()#desktop.CurrentComponent
    sel = doc.CurrentSelection
    sheet = sel.Spreadsheet
    data = sel.FormulaArray
    data = sorted([r[0] for r in data])
    out = [list(entries) for _, entries in groupby(data)]
    size = max(len(row) for row in out)
    for row in out:
        row.extend(['']*(size-len(row)))
    out = tuple(map(tuple,out))
    outrange = sheet.getCellRangeByPosition(1, 1, size, len(out))
    outrange.setFormulaArray(out)

@karolus - Wow you even wrote the macro. The answer “macro needed” would have been sufficient for my understanding. What you wrote now is - at least for my understanding - a detailed answer to the original question. Hope that @teraciv appreciates that.

My apologies, I lost my password and was not able to log in until now to thank you. Thank you very much!

another Solution without scripting is:

Formula in B1:

=REPT(A1&CHAR(9);COUNTIF(A$1:A$1000;A1))

pull down as far you need, copy Col B and paste_special without Options []all and []Formulas and in next Step do →Data→Text in Columns with [x]Tabulator as Delimiter

filter at last with Option [x]no Duplicates

Thank you very much again. I would upvote this, but I have too few points!