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'
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'
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)