One of the best features of Excel is that it’s quick and easy to sort columns of data. From what I’ve seen, sorting is one of the first things most people learn to do, when they’re getting started in Excel.

Sort Across Row
Usually, we sort Excel data based on a column’s values, but there are other options available for you.
You can even sort data in an Excel row, left to right, by changing one of the sort options.
This method sorts the columns in the entire list of data, based on the values in the selected row.
To see an example, watch the short video in the next section.

Video: Sort Data By Row Values
In this example, I show how to sort a table of monthly sales, so the month with the largest sales total is at the left. To do this, I used a right-click popup menu, for a custom sort.
Sort Multiple Rows of Data With a Formula
In a comment on the Sort a Row in Excel 2010 blog post, Debbie asked about sorting 2000 rows, individually, left to right.
She didn’t say they were lottery numbers, but her example, shown below, sure looks like that to me.

Sort With Formulas
One way to sort the rows is to use a formula, in columns to the right.
In the screen shot below, cells H1:M1 are selected, and this SMALL formula is entered:
=SMALL(A1:F1,{1,2,3,4,5,6})
Then, to array-enter the formula, press Ctrl+Shift+Enter
The formula sorts the 6 numbers from A1:F1, in ascending order, and shows the results in the 6 cells where the formula was array entered — H1:M1

Copy Formula Down
After you enter the formula in row 1, select cells H1:M1
Then, point to the fill handle at the bottom right of the selected range
When the pointer changes to a black fill handle, like the one in the screen shot below, drag down to the last row of numbers
Then, release the mouse button, and each row’s formula shows the row’s original numbers in ascending order.

Change to Values
After the formulas have been copied down to the last row of data, you can leave them as is.
Or, as a final step, you could copy the columns of formulas, and paste them as values. This short video shows a different Excel workbook, where I used a mouse shortcut to copy formulas, and paste them as values.
Sort Multiple Rows with a Macro
If you don’t want to mess with formulas, you could use a macro to sort each row, left to right.
The following macro, from Dave Peterson, will sort all the rows on the active sheet, starting in row 1, and assumes there are 6 columns of numbers.
Make a copy of your original worksheet, before sorting with the macro.
Sub SortLotteryRows()
'posted by Dave Peterson
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
With ActiveSheet
FirstRow = 1 'change to 2 if there are headings
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = FirstRow To LastRow
With .Cells(iRow, "A").Resize(1, 6)
.Sort Key1:=.Columns(1), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlLeftToRight
End With
Next iRow
End With
End Sub
Other Row Sorting Ideas
Do you have any other ideas for sorting lots of rows? Please share your ideas in the comments.
And for more Excel sorting tips, go to the Excel Sorting page on my Contextures site.
_____________
Debra,
It’s hard to go wrong with any code from Dave Peterson.
Also, your advice to:
“Make a copy of your original worksheet, before sorting with the macro.” should be heeded.
The following very similar code to Dave’s, allows one to sort rows in the selection.
(instead of a fixed location)
Also, the code might run a little faster as it eliminates the use of the Resize property.
It sorts ascending unless one specifies a descending sort.
Do that by adding the number 2 or the expression “xlDescending” to the GetMeStarted sub…
This sorts ascending… Call SortRowsAcross
This sorts descending… Call SortRowsAcross(xlDescending)
This also sorts descending… Call SortRowsAcross(2)
‘–code starts–
Sub GeMeStarted() Call SortRowsAcross End Sub Function SortRowsAcross(Optional ByRef lngDirection As Long = 1) Dim rngAll As Range Dim rngRw As Range Set rngAll = Selection For Each rngRw In rngAll.Rows rngRw.Sort key1:=rngRw, Order1:=lngDirection, header:=xlNo, _ MatchCase:=False, Orientation:=xlLeftToRight Next ‘rngRw End Function‘–code ends–
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
Thanks Jim!
Critical note. When sorting, make sure you sort the entire block of data. If you sort only some columns of a range, you’ll never be able to piece those rows together again.
There is an error in the array formula SMALL(A1:F1,{1,2,3,4,5,6})
The correct formula is SMALL(A1:F1,{1;2;3;4;5;6}) and Ctrl+Shift+Enter
Yes, if your regional settings use a semi-colon as the separator, you’ll have to change the formula to use those.
still do not work. sorry somebody knows why.?
Just a small comment on the procedure of using a formula to sort, I tried following instruction of using =SMALL(A1:F1,{1,2,3,4,5,6})
selecting multiple cells and Ctrl+shit+enter. It does not work.
Here is what does work, select cell “H” then add formula “small” select the range(A1:F1), then return 1, go to cell “I” and add formula and range, using return 2, same for J(3),K(4),L(5)&M(6). Each cell of the 6 is done separately and each returning a different position from 1-6, ie: 1st, 2nd, 3rd etc. for smallest values.
Then it will return the proper values and sort the numbers in order.
After that then you can drag the formula down the column and it will sort each set(row)in order.
And as mentioned, to keep the values, use select all and copy and paste special values when done for the array.
yes, this works perfectly
Yes.. indeed.. First Cell,SMALL(A1:F1,{1;2;3;4;5;6}), Second Cell,SMALL(A1:F1,{2;3;4;5;6}) Third,SMALL(A1:F1,{3;4;5;6}) etc… worked perfectly for me.. Thanks a whole bunch..