Hi all.
I have found the following piece of code which finds dupes in a comma delimited string and removes them. This works faultlesly:-
I now want to sort each element within the string in ascending order and have this "bubble" sort code:-
I'm sure I have used this before with great effect, but I cannot adapt it here. Keeps erroring at lngMin = LBound(arr) - type mismatch.
Is this the right method to sort and why is my code failing?
Many thanks in advance.
Regards.
I have found the following piece of code which finds dupes in a comma delimited string and removes them. This works faultlesly:-
Code:
Dim sString As String
Dim MyAr As Variant
Dim Col As New Collection
Dim itm, i
sString = Me.txt_CodeString
MyAr = Split(sString, ",")
For i = LBound(MyAr) To UBound(MyAr)
On Error Resume Next
Col.Add Trim(MyAr(i)), CStr(Trim(MyAr(i)))
On Error GoTo 0
Next i
sString = ""
For Each itm In Col
sString = sString & "," & itm
Next
sString = Mid(sString, 2)
Me.txt_CodeString = sString
'BubbleSort sString
Call BubbleSort(sString)
I now want to sort each element within the string in ascending order and have this "bubble" sort code:-
Code:
Dim strTemp As String
Dim i As Long
Dim j As Long
Dim lngMin As Long
Dim lngMax As Long
lngMin = LBound(arr)
lngMax = UBound(arr)
For i = lngMin To lngMax - 1
For j = i + 1 To lngMax
If arr(i) > arr(j) Then
strTemp = arr(i)
arr(i) = arr(j)
arr(j) = strTemp
End If
Next j
Next i
I'm sure I have used this before with great effect, but I cannot adapt it here. Keeps erroring at lngMin = LBound(arr) - type mismatch.
Is this the right method to sort and why is my code failing?
Many thanks in advance.
Regards.