How to sort columns from filled to empty

For example, one column has many colored cells while others have less. How to sort the columns such that the column with the most colored cells comes first and the least at the last?

Do I understand you right - you want to re-order your columns by the number of colorized cells in the column?

Yes or when the columns contains more data than the others.

Never heard of any way to sort columns (may be macros could achieve that, but can’t imagine any use case which would require such sort and justify such effort)

Anyway you can only sort columns for a range containing data.
Using >Data>Sort the selected range will auitomatically collapse to a rectangle without empty rows and columns at its borders.
Special sort criteria (based on counting something e.g.) must be calculated in advance.

The idea of sorting based on counting colored cells is really funny. Are you aware of the fact that there may be thousands of colors which even the best human eye cannot distinguish from white?

Do you also know that the default is “no color at all”? It is represented by the .CellBackColor value -1 which is an illegal value regarding the RGB color space.

Just for fun I add code (based on VBAsupport) which can count the cells inside a range not having the default -1 in the mentioned place.

REM  *****  BASIC  *****

Option VBAsupport 1

Function countNonDefaultBackColorCells(pRange)
countNonDefaultBackColorCells = "single range needed!"
On Local Error Goto fail
n = 0
passedRg = pRange.CellRange
ucfrgs = passedRg.UniqueCellFormatRanges
For Each rgs in ucfrgs
  For Each rg in rgs
    If rg.CellBackColor<>-1 Then n = n + (rg.Columns.Count * rg.Rows.Count)
  Next rg
Next rgs
countNonDefaultBackColorCells = n
fail:
End Function

Demo: ask247238funnySorting.ods