GSCaupling
Technical User
I found code for a function that will alphabetize the characters in a string.
If A2 is "TACO" then Sortletters(A2) returns "ACOT." What I'd like the result to look like is "A C O T" with a space in between the characters. A leading space before the first character is okay - I'm just looking for readability.
Here is the code:
Function SortLetters(v As Variant) As String
Dim bFlag As Boolean
Dim n As Long, i As Long
Dim s As String
n = Len(v)
If n = 0 Then Exit Function
ReDim arrS(0 To Len(v))
For i = 1 To Len(v)
arrS(i) = Mid$(v, i, 1)
Next
Do
bFlag = True
For i = LBound(arrS) To UBound(arrS) - 1
If arrS(i) > arrS(i + 1) Then
bFlag = False
arrS(0) = arrS(i)
arrS(i) = arrS(i + 1)
arrS(i + 1) = arrS(0)
End If
Next i
Loop While Not bFlag
s = ““
For i = 1 To UBound(arrS)
s = s & arrS(i)
Next
SortLetters = s
End Function
What would I add to get the spacing I want?
Thanks,
GS
[Green]******^*******
[small]I[/small] [small]Hate[/small] [♥] [small]Ambiguity.[/small][/green]
If A2 is "TACO" then Sortletters(A2) returns "ACOT." What I'd like the result to look like is "A C O T" with a space in between the characters. A leading space before the first character is okay - I'm just looking for readability.
Here is the code:
Function SortLetters(v As Variant) As String
Dim bFlag As Boolean
Dim n As Long, i As Long
Dim s As String
n = Len(v)
If n = 0 Then Exit Function
ReDim arrS(0 To Len(v))
For i = 1 To Len(v)
arrS(i) = Mid$(v, i, 1)
Next
Do
bFlag = True
For i = LBound(arrS) To UBound(arrS) - 1
If arrS(i) > arrS(i + 1) Then
bFlag = False
arrS(0) = arrS(i)
arrS(i) = arrS(i + 1)
arrS(i + 1) = arrS(0)
End If
Next i
Loop While Not bFlag
s = ““
For i = 1 To UBound(arrS)
s = s & arrS(i)
Next
SortLetters = s
End Function
What would I add to get the spacing I want?
Thanks,
GS
[Green]******^*******
[small]I[/small] [small]Hate[/small] [♥] [small]Ambiguity.[/small][/green]