Ask Your Question

How to sort columns in rows

asked 2017-08-20 05:33:03 +0200

seschenburg gravatar image

updated 2017-08-20 05:49:54 +0200

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

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2019-08-05 16:47:49 +0200

karolus gravatar image

@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]

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

edit flag offensive delete link more


ok ;-) just realize the original thread starts August/2017

karolus gravatar imagekarolus ( 2019-08-05 16:54:31 +0200 )edit

answered 2019-08-04 23:55:58 +0200

georgebueno gravatar image

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:

edit flag offensive delete link more

answered 2017-08-20 08:24:57 +0200

Lupp gravatar image

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.)

edit flag offensive delete link more


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

m.a.riosv gravatar imagem.a.riosv ( 2017-08-20 12:01:22 +0200 )edit

I see. Hmmm, 2000+ rows. bleh.

Ok, thanks.

seschenburg gravatar imageseschenburg ( 2017-08-20 14:19:56 +0200 )edit

it can be automated with a macro.

librebel gravatar imagelibrebel ( 2017-08-20 14:42:41 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-08-20 05:33:03 +0200

Seen: 1,722 times

Last updated: Aug 05