PDA

View Full Version : Solved: sort data on cell by value order



parscon
05-15-2012, 06:24 AM
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 .

Tinbendr
05-15-2012, 12:21 PM
try this.

Select cell you are interested in reordering and run OrderCell.

parscon
05-15-2012, 12:29 PM
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 .

Tinbendr
05-15-2012, 02:13 PM
Sorry, I don't understand your logic of order.

parscon
05-15-2012, 02:17 PM
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)

Tinbendr
05-15-2012, 02:35 PM
Do you want this incorporated in the other macro?

parscon
05-15-2012, 02:36 PM
Yes , exactly , that i want sort by my order .

Tinbendr
05-15-2012, 02:38 PM
Last edit. Gotta head out. Good luck!

Bob Phillips
05-15-2012, 02:38 PM
Run against the activecell


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

parscon
05-15-2012, 03:15 PM
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 .

Bob Phillips
05-16-2012, 12:21 AM
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.

Tinbendr
05-16-2012, 04:34 AM
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.

parscon
05-16-2012, 06:44 AM
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 .

parscon
05-17-2012, 08:22 AM
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 .

Tinbendr
05-17-2012, 08:46 AM
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.