How to change cell with value "A,E,D,C" to ascending order "A,C,D,E" by VBA?
How to change cell with value "A,E,D,C" to ascending order "A,C,D,E" by VBA?
Last edited by london7871; 10-13-2011 at 12:22 AM.
Try this:-
Data "A1" Resul;ts "A2".
Regards Mick![]()
Sub MG11Oct28 Dim Ray As Variant Dim Temp As String Dim I As Integer Dim j As Integer Ray = Split([a1], ",") For I = 1 To UBound(Ray) For j = I To UBound(Ray) If Ray(j) < Ray(I) Then Temp = Ray(I) Ray(I) = Ray(j) Ray(j) = Temp End If Next j Next I [a2] = Join(Ray, ",") End Sub
Dear Mick,
Thanks.
Regards.
Last edited by london7871; 10-13-2011 at 12:22 AM.
Hi london7871,
Look at http://www.ozgrid.com/VBA/sort-array.htm and the Sort Array routine.
Look to see if Arrays have the first element as the zero index for why the above didn't sort the "z" correctly.
One test is worth a thousand opinions.
Click the * Add Reputation below to say thanks.
Sorry try this:-
Mick![]()
Dim ray As Variant Dim temp As String Dim i As Integer Dim j As Integer ray = Split([a1], ",") For i = 0 To UBound(ray) For j = i To UBound(ray) If ray(j) < ray(i) Then temp = ray(i) ray(i) = ray(j) ray(j) = temp End If Next j Next i [a2] = Join(ray, ",")
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks