sort single row/multiple columns

r121a947

New member
Joined
Jun 29, 2019
Messages
49
Reaction score
0
Points
0
Excel Version(s)
Office 365
Is there a way to sort a portion of a single row over multiple columns, without having to specify a Sort by column?

I have individual words in several columns, and I want to sort the columns alphabetically, regardless of which column the words are in.

For example, each column from M to W has a single word. I want to sort that portion of the row so that the words are rearranged in the columns alphabetically, lowest in M, highest in W.

Thank you.
 
If you select the columns and do a sort left to right that should work.
 
I tried that . . . No success. It still asks for a Sort by criterion.

Thank you.
 
I am going to CROSS POST this on the Chandoo forum.
 
I did a manual sort and recorded it as a macro. The code is pasted below.

I am unable to get the proper syntax for the range, which would be columns M thru AH for each row.

Any help will be greatly appreciated.

Code:
Sub Jsort()
'
' Jsort Macro
' Sort the individual words in the J column cell
'
' Keyboard Shortcut: Ctrl+Shift+J
'
    Dim cur As Integer
    Dim i As Integer
    ' cur = 1
    
    
    
    For i = 1 To 16
    cur = i
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=ActiveCell. _
        Range("Mcur:AHcur"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("Mcur:AHcur")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlLeftToRight
        .SortMethod = xlPinYin
        .Apply
    End With
    Next i
End Sub
 
I received a solution . . .
Code:
Sub Jsort()
'
' Jsort Macro
' Sort the individual words in the J column cell
'
' Keyboard Shortcut: Ctrl+Shift+J
'
    Dim i As Integer
    
    
    
    For i = 1 To 16
        With ActiveWorkbook.Worksheets("Sheet1").Sort
            .SortFields.Clear
            .SortFields.Add Key:=Range("M" & i).Resize(, 22) _
                , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
                xlSortNormal
            .SetRange Range("M" & i).Resize(, 22)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlLeftToRight
            .SortMethod = xlPinYin
            .Apply
        End With
    Next i
End Sub
 
Back
Top