+ Reply to Thread
Results 1 to 4 of 4

alphabetizing/sorting text within a cell

  1. #1
    patrickchen@gmail.com
    Guest

    alphabetizing/sorting text within a cell

    hi,

    does anybody know how to alphabetize groups of words within a cell (by
    first letter of the word)?

    for instance, in a cell i have the words "dog bird cat" and after
    alphabetization it would come out as "bird cat dog"

    any help would be appreciated thanks


  2. #2
    JMB
    Guest

    RE: alphabetizing/sorting text within a cell

    You could use Text To Columns (delimiter = space) to split the data. Then
    use Excel's sort (Data/Sort), and concatenate the items back together into
    one string. Another possibility is to try a User Defined Function.

    Function MySort(rngCell As Range) As String
    Dim arrData As Variant
    Dim i As Long
    Dim t As Long
    Dim strTemp As String

    arrData = Split(rngCell.Value, " ", -1, vbTextCompare)

    For i = LBound(arrData) To UBound(arrData) - 1
    For t = i + 1 To UBound(arrData)
    If LCase(CStr(arrData(t))) < LCase(CStr(arrData(i))) Then
    strTemp = arrData(i)
    arrData(i) = arrData(t)
    arrData(t) = strTemp
    End If
    Next t
    Next i

    MySort = Join(arrData, " ")

    End Function

    "patrickchen@gmail.com" wrote:

    > hi,
    >
    > does anybody know how to alphabetize groups of words within a cell (by
    > first letter of the word)?
    >
    > for instance, in a cell i have the words "dog bird cat" and after
    > alphabetization it would come out as "bird cat dog"
    >
    > any help would be appreciated thanks
    >
    >


  3. #3
    patrickchen@gmail.com
    Guest

    Re: alphabetizing/sorting text within a cell

    Thanks, the function worked really well!


  4. #4
    JMB
    Guest

    Re: alphabetizing/sorting text within a cell

    Glad to help

    "patrickchen@gmail.com" wrote:

    > Thanks, the function worked really well!
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1