'Excel formula to take string value from cell and sort its characters in alphabetical order

Can you please help me to make Excel formula that takes string value from cell and sorts its characters in alphabetical order?

Ex.

original cell value: 'BACR' sorted characters cell: 'ABCR'



Solution 1:[1]

EDIT 2022-04-29:

With the advent of dynamic formula introduced in Office 365 Excel we can use an easy formula to do this:

=CONCAT(SORT(MID(A1,SEQUENCE(,LEN(A1)),1),1,1,TRUE))

Original:

This UDF will sort numbers and Text character by character:

Function sortletter(rng As Range)
    If rng.Count > 1 Then Exit Function
    Dim srtArr() As String
    Dim i&, j&, k&
    ReDim srtArr(1 To Len(rng))
    srtArr(1) = Mid(rng, 1, 1)
    For i = 2 To UBound(srtArr)
        For j = 1 To UBound(srtArr)
            If srtArr(j) = "" Then
                srtArr(j) = Mid(rng, i, 1)
                Exit For
            ElseIf IIf(Asc(Mid(rng, i, 1)) > 96, Asc(Mid(rng, i, 1)) - 32, Asc(Mid(rng, i, 1))) <= IIf(Asc(srtArr(j)) > 96, Asc(srtArr(j)) - 32, Asc(srtArr(j))) Then
                For k = UBound(srtArr) To j + 1 Step -1
                    srtArr(k) = srtArr(k - 1)
                Next k
                srtArr(j) = Mid(rng, i, 1)
                Exit For
            End If
        Next j
    Next i
    sortletter = Join(srtArr, "")
End Function

Put this is a module attached to the workbook, NOT in the worksheet or ThisWorkbook code.

Then it can be called like any other formula

=sortletter(A1)

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1