[VBA/Excel] Ascending Sort in a Column

sfritz Posted messages 49 Status Membre -  
pilas31 Posted messages 1878 Status Contributeur -
Hello,
I would like to sort numbers in ascending order in a column.
I would like to know if there is a sort function (or something equivalent), or if I have to create code to sort these values.

If there is a function, please specify which one, along with a small example if possible.

Thank you.

3 réponses

pilas31 Posted messages 1878 Status Contributeur 648
 
Hello,

In VBA, there is a sort function. Here is a simple example to sort column A in ascending order:

 Columns("A:A").Select Selection.Sort Key1:=Range("A1") 


There are many parameters in the "sort" function, please tell us more so that we can provide a more complete example.

Best regards,
16
apprentigeek
 
And how do we use this function so that the other data in the table from the other columns follows?
0
jc80 Posted messages 5063 Registration date   Status Membre Last intervention   1 442 > apprentigeek
 
Hello
For example from A to H

Columns("A:H").Select
Selection.Sort Key1:=Range("A1")
Best regards
-1
Squalleh
 
I still don’t understand the point of doing a select...
Columns("A:H").Sort Key1:=Range("A1") is so much nicer to read...

EDIT: you can even do without the second range by replacing it with a cells, at least... But oh well ^^
0
pilas31 Posted messages 1878 Status Contributeur 648 > Squalleh
 
Hello Squalleh,

I completely agree.
We need to track the Select statements to optimize the code.
In my initial post 7 and a half years ago, I was probably not yet aware enough of this aspect.

Best regards,
0