Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort order keeping names together 1

Status
Not open for further replies.

raven1

Technical User
Aug 1, 2002
37
0
0
US
Does anyone know if it possble to sort first and last names ascending and still keep them alphabetically orders in each column?
example
Bob smith
Alan smith
Carol brown
I want all last names to stay together with first names sorted ascending.Is this possible or is something that needs to be done in access?
Thanx!
 
If first and last names are in seperate columns, just set the order in the sort dialog box to last name then first name.

If they are in the same column, use the text to column function to seperate them into two columns (with the space as your delimiter) and then set the sort order.

Sam
 
Hi
This is the same thing in code
Code:
Sub SortNames()

Dim c As Range
    With Range("A1")
        .CurrentRegion.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Space:=True, _
            Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1))
        .Select
        Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("A1") _
            , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
            False, Orientation:=xlTopToBottom
        For Each c In .CurrentRegion.Columns(1).Cells
            c.Value = c.Text & " " & c.Offset(0, 1).Text
        Next
        .CurrentRegion.Columns(2).Cells.ClearContents
    End With
End Sub

This seperates, sorts and brings the names back together.

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top