Arrange numbers small to big in ascending order

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Using Excel 2010

Hello,

I have number in columns D:H I want a macro which can make them in ascending order from n1 through n5 small to bigger number or A to Z

Note: I want a macro which can be used in Excel 2000 that has only 3 fileds to make them in order. But here are the 5 fileds.

Here is the descending order data example.

Excel Question ExcelFourms.xls
ABCDEFGHIJ
1
2
3
4
5n1n2n3n4n5
656789
7467810
8457910
9367910
10358910
11268910
12178910
13457811
14367811
15456911
16357911
17267911
18348911
19258911
20168911
213561011
223471011
232571011
241671011
252481011
261581011
272391011
281491011
29456812
30357812
31267812
32356912
33347912
34257912
35167912
36248912
37158912
383461012
392561012
402471012
411571012
422381012
431481012
441391012
453451112
462461112
471561112
482371112
491471112
501381112
511291112
52456713
53356813
54347813
55257813
56167813
57346913
58256913
59247913
60157913
61238913
62148913
633451013
642461013
651561013
662371013
671471013
681381013
691291013
702451113
712361113
721461113
731371113
741281113
752351213
761451213
771361213
781271213
79356714
80346814
81256814
82247814
83157814
84345914
85246914
86156914
87237914
88147914
89138914
902451014
912361014
921461014
931371014
941281014
952351114
961451114
971361114
981271114
992341214
1001351214
1011261214
1021341314
1031251314
104346715
105256715
106345815
107246815
108156815
109237815
110147815
111245915
112236915
113146915
114137915
115128915
1162351015
1171451015
1181361015
1191271015
1202341115
1211351115
1221261115
1231341215
1241251215
1251241315
1261231415
127345716
128246716
129156716
130245816
131236816
132146816
133137816
134235916
135145916
136136916
137127916
1382341016
1391351016
1401261016
1411341116
1421251116
1431241216
1441231316
145345617
146245717
147236717
148146717
149235817
150145817
151136817
152127817
153234917
154135917
155126917
1561341017
1571251017
1581241117
1591231217
160245618
161235718
162145718
163136718
164234818
165135818
166126818
167134918
168125918
1691241018
1701231118
171235619
172145619
173234719
174135719
175126719
176134819
177125819
178124919
1791231019
180234620
181135620
182134720
183125720
184124820
185123920
186234521
187134621
188125621
189124721
190123821
191134522
192124622
193123722
194124523
195123623
196123524
197123425
198
199
200
201
202
203
204
Sheet4

Thank you.


Regards,
Moti
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi @motilulla. I hope you're well.

I want a macro which can be used in Excel 2000 that has only 3 fileds to make them in order. But here are the 5 fileds.

In the following macro change xlAscending to xlDescending if you want them from highest to lowest.

Change the 5 to 3 if you need 3 columns.

In the macro I am highlighting the data that you can change.
Rich (BB code):
Sub Arrange_Numbers()
  Dim c As Range
  Application.ScreenUpdating = False
  For Each c In Range("D6", Range("D" & Rows.Count).End(3))
    c.Resize(1, 5).Sort c, xlAscending, Header:=xlNo, Orientation:=xlSortRows
  Next
  Application.ScreenUpdating = True
End Sub

--------------​
Let me know the result and I'll get back to you as soon as I can.​
Cordially​
Dante Amor
--------------​
 
Upvote 0
Hi @motilulla. I hope you're well.



In the following macro change xlAscending to xlDescending if you want them from highest to lowest.

Change the 5 to 3 if you need 3 columns.

In the macro I am highlighting the data that you can change.
Rich (BB code):
Sub Arrange_Numbers()
  Dim c As Range
  Application.ScreenUpdating = False
  For Each c In Range("D6", Range("D" & Rows.Count).End(3))
    c.Resize(1, 5).Sort c, xlAscending, Header:=xlNo, Orientation:=xlSortRows
  Next
  Application.ScreenUpdating = True
End Sub

--------------​
Let me know the result and I'll get back to you as soon as I can.​
Cordially​
Dante Amor
--------------​
Hello @Dante Amor. Yes thank you all is fine. Hope you are also find healthy.

I as usually insert module and placed macro I run it several times but seems does not happen any action, please can you check or advise what I am missing.

Kind Regards,
Moti
 
Upvote 0
I as usually insert module and placed macro I run it several times but seems does not happen any action, please can you check or advise what I am missing.
The macro is very fast.

Change xlAscending to xlDescending so you can see the changes


Then change them again, you will see how the numbers change.
 
Upvote 0
In your example, the data is already ordered from smallest to largest. So the macro sorts them from smallest to largest, that's what you asked for.
So apparently no change.
That's why I ask you please to change the order in the macro to xlDescending

Then change them again to xlAscending

--------------
I hope to hear from you soon.
Respectfully
Dante Amor
--------------
 
Upvote 0
The macro is very fast.

Change xlAscending to xlDescending so you can see the changes


Then change them again, you will see how the numbers change.
Ok. Dante Amor. Yes true changing that as you say I can see the effect but I realize it is my mistake I want to sort as show below here is an example with 10 rows as @Peter_SSs asked. For example in cells D6:H15 there are original data I want to sort them as shown in the Cells D21:H30 first n1 then n2 then n3 then n4 then n5. I mean Column wise

Excel Question ExcelFourms.xls
ABCDEFGHIJ
1
2
3
4
5n1n2n3n4n5
656789
7178910
8258911
92571011
10158912
113451112
12356714
13157814
14138914
15234917
16
17
18
19
20n1n2n3n4n5
21138914
22157814
23158912
24178910
25234917
262571011
27258911
283451112
29356714
3056789
31
32
33
34
35
Sheet5


Thank you

Kind Regards,
Moti
 
Last edited:
Upvote 0
For that you can do it with the functionality of excel ordering by 5 levels:

1685497600382.png
 
Upvote 0
Try this macro:

VBA Code:
Sub Macro4()
  Dim lr As Long

  lr = Range("D" & Rows.Count).End(3).Row
  With ActiveSheet.Sort
    .SortFields.Clear
    .SortFields.Add Key:=Range("D6:D" & lr), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .SortFields.Add Key:=Range("E6:E" & lr), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .SortFields.Add Key:=Range("F6:F" & lr), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .SortFields.Add Key:=Range("G6:G" & lr), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .SortFields.Add Key:=Range("H6:H" & lr), _
      SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
      .SetRange Range("D5:H" & lr)
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
End Sub
 
Upvote 1

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top