Results 1 to 24 of 24

Can you sort data alphabetically in one particular cell?

Threaded View

  1. #3
    Registered User
    Join Date
    05-24-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Can you sort data alphabetically in one particular cell?

    Can be done with a user defined function.



    Function SortWithinCell(CelltoSort As Range, DelimitingCharacter As String, IncludeSpaces As Boolean) As String
    CelltoSortString = WorksheetFunction.Substitute(CelltoSort.Value, " ", "")
    MyArray = Split(CelltoSortString, DelimitingCharacter)
        For N = 0 To UBound(MyArray)
            For M = 1 To UBound(MyArray)
                
                    If MyArray(M) < MyArray(M - 1) Then
                        TempValue = MyArray(M)
                        MyArray(M) = MyArray(M - 1)
                        MyArray(M - 1) = TempValue
                    End If
    
            Next M
        Next N
    For N = 0 To UBound(MyArray)
        SortWithinCell = SortWithinCell & MyArray(N) & DelimitingCharacter
    Next N
    SortWithinCell = Left(SortWithinCell, Len(SortWithinCell) - 1)
    If IncludeSpaces = True Then SortWithinCell = WorksheetFunction.Substitute(SortWithinCell, ",", ", ")
    End Function
    Alt F11 to open the VBA editor. Insert - module. Paste in the above. Alt F11 back to worksheet,

    In B1 enter

    =SortWithinCell(A1,",",TRUE)

    assuming starting string is in A1



    Way above my head, would you mind dumbing it down just a bit? I really appreciate your help.
    Last edited by arlu1201; 11-01-2012 at 07:18 AM.

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