Consulting

Results 1 to 15 of 15

Thread: Solved: sort data on cell by value order

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Question Solved: sort data on cell by value order

    I have data on column A and cell1 that mean A1 like this :

    123(BN), 1234(MN), DATA2, L320LM

    and i want to order them like :

    DATA2, 123(BN), L320LM, 1234(MN) , That mean order all my data on column A will be by this DATA2, 123(BN), L320LM, 1234(MN) .

    Thank you for your help .
    Last edited by parscon; 05-15-2012 at 06:57 AM.

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    try this.

    Select cell you are interested in reordering and run OrderCell.
    Attached Files Attached Files

    David


  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Really Thank you for your help . Thank you so much . but it is not work .

    I have some data and want sort all cell data on column .

    Please check the enclosed file . i want sort all cell in column A like A1 cell .

    Thank you so much and hope pardon me for many request .
    Attached Files Attached Files
    Last edited by parscon; 05-15-2012 at 12:43 PM.

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Sorry, I don't understand your logic of order.

    David


  5. #5
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Example : I want order my data on cell like :

    1,2,3,4,5,6,7,8,9,10 (order value)

    Now my real data is different like : A32,A45, A46 ,... that mean when order the if A32 available in cell will be the first after that A45 and A46 and others..


    and i have these data on cell A1 :

    6,10,7

    when run macro , it will be 6,7,10

    A2 cell : 2,5,4,1,8,10

    and when run VBA it will be : 1, 2, 4, 5, 8 , 10

    and i need this for all cell in column A

    Hope you will understand what i need .


    Real Example : i want order my data on cell like : L120(BM), L120B(BM), L250G, L350F, L90C(BM), L90C

    Now i have data on A1 like : L250G ,L120(BM), L90C(BM)

    when run Macro code it will be L120(BM), L250G, L90C(BM)

  6. #6
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Do you want this incorporated in the other macro?

    David


  7. #7
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Yes , exactly , that i want sort by my order .

  8. #8
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Last edit. Gotta head out. Good luck!
    Attached Files Attached Files

    David


  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Run against the activecell

    [VBA]
    Sub OrderCell()
    Dim ary As Variant
    Dim tmp As Variant
    Dim allSorted As Boolean
    Dim i As Long

    With ActiveCell

    ary = Split(.Value, ",")
    Do

    allSorted = True
    For i = LBound(ary) To UBound(ary) - 1

    If ary(i) > ary(i + 1) Then

    tmp = ary(i)
    ary(i) = ary(i + 1)
    ary(i + 1) = tmp
    allSorted = False
    End If
    Next i
    Loop Until allSorted

    .Value = Join(ary, ",")
    End With
    End Sub
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you very much xld and Tinbendr for your big help .

    but you did not understand what i need .

    "Farm", "Paddock", "Sheep", "Cow", "Bird", "Mice", "Chicken", "Fence", "Post", "Lamb"


    in Cell A1 : i have : Mice,Fence,Sheep

    i need VBA when run order in cell A1 will be Sheep, Mice, Fence

    Finally that mean order by my data order ("Farm", "Paddock", "Sheep", "Cow", "Bird", "Mice", "Chicken", "Fence", "Post", "Lamb")

    if i have Farm that it will be in latest it will be the first in my cell after run VBA .

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well, I think we can agree on one thing. We, I certainly, do not understand what you mean.

    But I find your predilection to have multiple values in a single cell to be ridiculous. The work required to manage that testifies to the ridiculousness, so I for one will be avoiding any further questions where the data is thus formed.
    Last edited by Bob Phillips; 05-16-2012 at 06:50 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    I was afraid that was what you meant.

    Sorting of ordinal values can be most labor intensive. You'd have to create a map of how the order should be and that's a little over my head. I'll check into it today and see if I can find anything that would work.

    That's why I wrote the other code with the userform. At least you can sort them manually.

    David


  13. #13
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you again xld and Tinbender . Hope can find way for this problem. i have about 28000 cell in Column A with their data and must sort them with main data and it will take lot of time for check all of them manually .

  14. #14
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    we have the data that mean like value "" check the value and order with value .

    if in value orde will be like this "Apple , Orange , Ben , 12345 , 4321"

    data an cell will be like this that mean if we have these data on cell :

    Ben, 12345 , Apple when run VBA Apple will be the first and after that Ben and finally 12345 .

    that mean in VBA i must have a place to enter my value and order will be by my value in each cell of column .

  15. #15
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    I did check around and all the examples I saw had a map/list of the order.

    I've gone as far as I can until I have that.

    On a seperate sheet, make the list (the real data) and u/l test file again.

    David


Posting Permissions

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