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
 
You are correct that I can do in excel 2010 but we don’t have option in excel 2000 so far need a macro sort them please is it possible?
The macro is in post #9.

I put it again:

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

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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
@Dante Amor. That is spot on this did the excellent job in a milliseconds. 🤝

I appreciate your time and help and sorry for the inconvenient

Have a nice day and good luck!

Kind Regards,
Moti :)
 
Upvote 1
Note: I want a macro which can be used in Excel 2000 that has only 3 fileds to make them in order.

but we don’t have option in excel 2000 so far need a macro sort them please is it possible?
What happened to the above requirements?
Wouldn't this simple one work in all versions?

VBA Code:
Sub SortWith3()
  With Range("D5", Range("D" & Rows.Count).End(xlUp)).Resize(, 5)
    .Sort Key1:=.Columns(4), Order1:=xlAscending, Key2:=.Columns(5), Order2:=xlAscending, Header:=xlYes
    .Sort Key1:=.Columns(1), Order1:=xlAscending, Key2:=.Columns(2), Order2:=xlAscending, Key3:=.Columns(3), Order3:=xlAscending, Header:=xlYes
  End With
End Sub
 
Upvote 1
Solution
What happened to the above requirements?
Wouldn't this simple one work in all versions?

VBA Code:
Sub SortWith3()
  With Range("D5", Range("D" & Rows.Count).End(xlUp)).Resize(, 5)
    .Sort Key1:=.Columns(4), Order1:=xlAscending, Key2:=.Columns(5), Order2:=xlAscending, Header:=xlYes
    .Sort Key1:=.Columns(1), Order1:=xlAscending, Key2:=.Columns(2), Order2:=xlAscending, Key3:=.Columns(3), Order3:=xlAscending, Header:=xlYes
  End With
End Sub
Hello Peter_SSs,

No doubt this version is far better I will go with this universal for all version option.

Thank you for your help and time for giving another choice. 🤝

Have a nice day and good luck!

Kind Regards,
Moti :)
 
Upvote 0
You're welcome. Glad to contribute. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,087
Messages
6,123,046
Members
449,092
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