Hi Tom,
The sort Left to Right option will stick so next time you have
to check that you have the correct option, but you would see rows
instead of columns.
Each row is independent so you cannot sort the range
all at one time but must do one row at a time,
sorting the data in the columns of each row per row..
You will need a macro, if you need help with installing/using
a macro see my page Getting Started with Macros
http://www.mvps.org/dmcritchie/excel/getstarted.htm
Function is not what you would use. A function cannot change
another cell. You might want to take a look at one of Chip
Pearson's page for the difference between a macro and a function.
Macros as Opposed to Functions (as found in topic.htm)
http://www.cpearson.com/excel/differen.htm
I had created a macro
Option Explicit
Sub Macro28()
'sort columns in each row within range B2:E28
Dim R As Long
For R = 2 To 28
Range("B" & R & ":E" & R).Sort key1:=Range("B" & R), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
Next R
End Sub
but then I looked at my webpage
http://www.mvps.org/dmcritchie/excel/sorting.htm
and saw that Tom Ogilvy had posted a better one but for columns:
Sub sortEachColumn()
'Tom Ogilvy, 2001-03-24, Programming
Dim col As Range
For Each col In Range("a2:g100").Columns
col.Sort key1:=col, Order1:=xlAscending
Next
End Sub
'-- so a modification to sort on each row instead of each column
'-- I also changed it to sort a selection rather than a specific range
'-- but you can change that to your requirement.
Sub sortEachRow()
'based on Tom Ogilvy, 2001-03-24, Programming
Dim rw As Range
If Selection.Columns.Count = 1 Then
MsgBox "your selection must involve more than one cell or column"
Exit Sub
End If
For Each rw In Selection.Rows
rw.Sort key1:=rw, Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
Next
End Sub