How to sort columns in rows

I’ve a block of columns and rows that are similar to this:

  • 1 |8 |38|47|43
  • 21|32|3 |37|26
  • 23|12|33|65|51

and I want them to sort into this:

  • 1 |8 |38|43|47
  • 3 |21|26|32|37
  • 12|23|33|51|65

IOW, I want the columns in each row to reorder such that the number values increase to the right. I select a block of cells…Sort…enable the Left to Right (Sort Columns) feature…OK, but it only works on one row at a time, even if I have multiple rows selected in the block. What am I doing wrong?

LibreOffice 5.3 with latest updates
TIA

If you sort a 2D range the first sortkey will apply.
Additional columns/rows will join the first one. That’s the behaviour mostly needed.
You cannot change that. (Neither if a column is used as first key (option top down) nor if it is a row (option left to right.)

With a bit of work, selecting and sorting row by row.

I see. Hmmm, 2000+ rows. bleh.

Ok, thanks.

it can be automated with a macro.

hello, you can use a function to solve your problem. Type this =SMALL($A1:$E1,COLUMN()-6) at G1 cell
and copy it till K3 (if you have 5 columns and 3 rows). It worked greatly for me, but please don’t ask me for details because I just don’t know. Ijust made the same question in the portuguese (pt-br) forum and got the answer from a real spreadsheet’s master.

Original answer: Como ordenar dados na horizontal de modo pratico?

@librebel
a kind of nobrainer in python:

def sort_rows_individually(*_):
    """    
    sorts row by row individually 
    in one selected  Cellrange
    """   
    doc = XSCRIPTCONTEXT.getDocument()
    selection = doc.getCurrentSelection()
    inData = selection.DataArray
    outData = [sorted(row) for row in inData]
    selection.setDataArray(outData)

tested with an 15cols x 30000rows Array of random numbers on a RaspberryPi3

ok :wink: just realize the original thread starts August/2017