Hi everyone.
I want to sort data in a range, the key is numbers, my data key look like this :
The problem is, in my real world, 1112 is actually less than 516, so to sort properly, i need to make 516 become 5160, 119 become 1190 and so on.
I use this code to sort :
Solution in my head is "format that range before sort action", so i add this code :
That codes doesn't work
I can't use looping because i have hundred thousand data in my range, looping on com object just make it slower, i can't use array because bubble sort on array is very slow, i can't use quick sort because it only support 1 key (i have to sort on multiple keys).
So, any suggestion?
I want to sort data in a range, the key is numbers, my data key look like this :
The problem is, in my real world, 1112 is actually less than 516, so to sort properly, i need to make 516 become 5160, 119 become 1190 and so on.
I use this code to sort :
VBA Code:
With oWs.Sort
.SortFields.Clear
.SortFields.Add Key:=oWs.Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
.SetRange oWs.Range("A1:K" & iLastRow)
.Header = xlNo
.Apply
End With
Solution in my head is "format that range before sort action", so i add this code :
Code:
oWs.Range("A:A").NumberFormat = "#000"
Code:
oWs.Range("A:A").NumberFormat = "0000"
That codes doesn't work
I can't use looping because i have hundred thousand data in my range, looping on com object just make it slower, i can't use array because bubble sort on array is very slow, i can't use quick sort because it only support 1 key (i have to sort on multiple keys).
So, any suggestion?