Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi CG
Sub test() MsgBox SortString("bv-8,ok-3,bv-5,sk-1,bh-2,ok-9", ",") End Sub Function SortString(S As String, Separator As String) As String Dim X() As String Dim tmp As String Dim i As Long, j As Long 'split: X = Split(S, ",") 'trim: For i = LBound(X) To UBound(X) X(i) = Trim$(X(i)) Next 'sort: For i = LBound(X) To UBound(X) - 1 For j = LBound(X) To UBound(X) - 1 If X(j) X(j + 1) Then tmp = X(j + 1) X(j + 1) = X(j) X(j) = tmp End If Next Next 'rebuild: tmp = "" For i = LBound(X) To UBound(X) tmp = tmp & X(i) & "," Next tmp = Left(tmp, Len(tmp) - 1) SortString = tmp End Function HTH. Best wishes Harald "CG Rosen" wrote in message ... Hi Group Trying to sort a string looking like: bv-8,ok-3,bv-5,sk-1,bh-2,ok-9 etc into: bh-2,bv-5,bv-8,ok-3,ok-9,sk-1 etc Grateful for some help. Brgds CG Rosen |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can you sort one cell or a string in vba? | Excel Programming | |||
Sort does not preserve string of additions | Excel Worksheet Functions | |||
Convert a string value to numeric and sort | Excel Programming | |||
Sort collection string keys | Excel Programming | |||
sort (on part of) string - originally posted under Tricky Sort | Excel Programming |