+ Reply to Thread
Results 1 to 5 of 5

Change cell from "A,E,D,C" to "A,C,D,E"

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Change cell from "A,E,D,C" to "A,C,D,E"

    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.

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Change cell from "A,E,D,C" to "A,C,D,E"

    Try this:-
    Data "A1" Resul;ts "A2".
    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
    Regards Mick

  3. #3
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Change cell from "A,E,D,C" to "A,C,D,E"

    Dear Mick,

    Thanks.

    Regards.
    Last edited by london7871; 10-13-2011 at 12:22 AM.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,303

    Re: Change cell from "A,E,D,C" to "A,C,D,E"

    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.

  5. #5
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Change cell from "A,E,D,C" to "A,C,D,E"

    Sorry try this:-
    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, ",")
    Mick

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1