Reordering rows in ascending order

sezuh

Well-known Member
Joined
Nov 19, 2010
Messages
708
Hi,
would you please tell me how to reorder cells or rows in ascending order
either with excel formula or vb code.
here is an example;
<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD><TD>J</TD><TD>K</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>List</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD>31 29 24</TD><TD style="TEXT-ALIGN: right">03 04 05</TD><TD> 19 21 20</TD><TD style="TEXT-ALIGN: right">06 10 14</TD><TD>22 30 26</TD><TD style="TEXT-ALIGN: right">07 12 17</TD><TD>23 33 28</TD><TD style="TEXT-ALIGN: right">15 08 13</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 02 18</TD><TD style="TEXT-ALIGN: right">11 16 09</TD><TD>27 25 32</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="TEXT-ALIGN: right">06 16 29</TD><TD style="TEXT-ALIGN: right">02 04 21</TD><TD style="TEXT-ALIGN: right"> 18 05 20</TD><TD style="TEXT-ALIGN: right">07 11 15</TD><TD>23 31 27</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 03 19</TD><TD>22 13 32</TD><TD style="TEXT-ALIGN: right">14 12 25</TD><TD style="TEXT-ALIGN: right">30 09 28</TD><TD style="TEXT-ALIGN: right">10 08 33</TD><TD>26 17 24</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD>Expected Result</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 02 18</TD><TD style="TEXT-ALIGN: right">03 04 05</TD><TD style="TEXT-ALIGN: right">06 10 14</TD><TD style="TEXT-ALIGN: right">07 12 17</TD><TD style="TEXT-ALIGN: right">08 13 15</TD><TD style="TEXT-ALIGN: right">09 11 16 </TD><TD> 19 20 21</TD><TD>22 26 30</TD><TD>23 28 33</TD><TD>24 29 31</TD><TD>25 27 32</TD></TR></TBODY></TABLE>

Excel tables to the web >> Excel Jeanie HTML 4

thank you very much indeed ror any help or suggestions.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG30Jul26
[COLOR="Navy"]Dim[/COLOR] oRng        [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] oDn         [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Rng         [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] i           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] j           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Dn          [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Temp        [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] cNum        [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] oRng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] oDn [COLOR="Navy"]In[/COLOR] oRng
        [COLOR="Navy"]Set[/COLOR] Rng = oDn.Resize(, 11)
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
                cNum = Split(Dn, " ")
                [COLOR="Navy"]For[/COLOR] i = 0 To UBound(cNum)
                    [COLOR="Navy"]For[/COLOR] j = i To UBound(cNum)
                        [COLOR="Navy"]If[/COLOR] cNum(j) < cNum(i) [COLOR="Navy"]Then[/COLOR]
                            Temp = cNum(i)
                            cNum(i) = cNum(j)
                            cNum(j) = Temp
                        [COLOR="Navy"]End[/COLOR] If
                    [COLOR="Navy"]Next[/COLOR] j
                [COLOR="Navy"]Next[/COLOR] i
                    Dn = Join(cNum, " ")
            [COLOR="Navy"]Next[/COLOR] Dn
        [COLOR="Navy"]For[/COLOR] i = 1 To Rng.Count
            [COLOR="Navy"]For[/COLOR] j = i To Rng.Count
                [COLOR="Navy"]If[/COLOR] Left(Rng(j), 2) < Left(Rng(i), 2) [COLOR="Navy"]Then[/COLOR]
                    Temp = Rng(i).Value
                    Rng(i) = Rng(j).Value
                    Rng(j) = Temp
                [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]Next[/COLOR] j
        [COLOR="Navy"]Next[/COLOR] i
    [COLOR="Navy"]Next[/COLOR] oDn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi,
Thanks Mick, your code work with a small glitch in that specific list but it work perfect with other lists,very much appreciated.here the example ,but you do not have to do anything it just to show you what i mean by glitch;
Sheet1

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 122px"><COL style="WIDTH: 89px"><COL style="WIDTH: 89px"><COL style="WIDTH: 89px"><COL style="WIDTH: 93px"><COL style="WIDTH: 93px"><COL style="WIDTH: 93px"><COL style="WIDTH: 93px"><COL style="WIDTH: 93px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD><TD>J</TD><TD>K</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD style="COLOR: #00ccff">List</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 02 18</TD><TD style="TEXT-ALIGN: right">03 04 05</TD><TD> 19 21 20</TD><TD style="TEXT-ALIGN: right">06 10 14</TD><TD>22 30 26</TD><TD style="TEXT-ALIGN: right">07 12 17</TD><TD>23 33 28</TD><TD style="TEXT-ALIGN: right">15 08 13</TD><TD>31 29 24</TD><TD style="TEXT-ALIGN: right">11 16 09</TD><TD>27 25 32</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 03 19</TD><TD style="TEXT-ALIGN: right">02 04 21</TD><TD style="TEXT-ALIGN: right"> 18 05 20</TD><TD style="TEXT-ALIGN: right">07 11 15</TD><TD>23 31 27</TD><TD style="TEXT-ALIGN: right">06 16 29</TD><TD>22 13 32</TD><TD style="TEXT-ALIGN: right">14 12 25</TD><TD style="TEXT-ALIGN: right">30 09 28</TD><TD style="TEXT-ALIGN: right">10 08 33</TD><TD>26 17 24</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 04 20</TD><TD style="TEXT-ALIGN: right">02 05 19</TD><TD style="TEXT-ALIGN: right"> 18 03 21</TD><TD style="TEXT-ALIGN: right">08 12 16</TD><TD>24 32 28</TD><TD style="TEXT-ALIGN: right">10 09 31</TD><TD>26 15 25</TD><TD style="TEXT-ALIGN: right">06 17 27</TD><TD style="TEXT-ALIGN: right">22 11 33</TD><TD>14 13 23</TD><TD style="TEXT-ALIGN: right">30 07 29</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">01 05 21</TD><TD style="TEXT-ALIGN: right">02 03 20</TD><TD style="TEXT-ALIGN: right"> 18 04 19</TD><TD style="TEXT-ALIGN: right">09 13 17</TD><TD>25 33 29</TD><TD style="TEXT-ALIGN: right">14 11 24</TD><TD style="TEXT-ALIGN: right">30 08 27</TD><TD style="TEXT-ALIGN: right">10 07 32</TD><TD>26 16 23</TD><TD style="TEXT-ALIGN: right">06 15 28</TD><TD style="TEXT-ALIGN: right">22 12 31</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD style="FONT-WEIGHT: bold; COLOR: #ff0000; TEXT-ALIGN: left">Result after code</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD>19 20 21 </TD><TD style="TEXT-ALIGN: right">01 02 18</TD><TD style="TEXT-ALIGN: right">03 04 05</TD><TD style="TEXT-ALIGN: right">06 10 14</TD><TD style="TEXT-ALIGN: right">07 12 17</TD><TD style="TEXT-ALIGN: right">08 13 15</TD><TD style="TEXT-ALIGN: right">09 11 16</TD><TD>22 26 30</TD><TD>23 28 33</TD><TD>24 29 31</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">25 27 32</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">8</TD><TD style="TEXT-ALIGN: right">05 18 20 </TD><TD style="TEXT-ALIGN: right">01 03 19</TD><TD style="TEXT-ALIGN: right">02 04 21</TD><TD style="TEXT-ALIGN: right">06 16 29</TD><TD style="TEXT-ALIGN: right">07 11 15</TD><TD style="TEXT-ALIGN: right">08 10 33</TD><TD style="TEXT-ALIGN: right">09 28 30</TD><TD style="TEXT-ALIGN: right">12 14 25</TD><TD>13 22 32</TD><TD>17 24 26</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">23 27 31</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">9</TD><TD style="TEXT-ALIGN: right">03 18 21 </TD><TD style="TEXT-ALIGN: right">01 04 20</TD><TD style="TEXT-ALIGN: right">02 05 19</TD><TD style="TEXT-ALIGN: right">06 17 27</TD><TD style="TEXT-ALIGN: right">07 29 30</TD><TD style="TEXT-ALIGN: right">08 12 16</TD><TD style="TEXT-ALIGN: right">09 10 31</TD><TD style="TEXT-ALIGN: right">11 22 33</TD><TD>13 14 23</TD><TD>15 25 26</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">24 28 32</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">10</TD><TD style="TEXT-ALIGN: right">04 18 19 </TD><TD style="TEXT-ALIGN: right">01 05 21</TD><TD style="TEXT-ALIGN: right">02 03 20</TD><TD style="TEXT-ALIGN: right">06 15 28</TD><TD style="TEXT-ALIGN: right">07 10 32</TD><TD style="TEXT-ALIGN: right">08 27 30</TD><TD style="TEXT-ALIGN: right">09 13 17</TD><TD style="TEXT-ALIGN: right">11 14 24</TD><TD style="TEXT-ALIGN: right">12 22 31</TD><TD>16 23 26</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">25 29 33</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">11</TD><TD style="FONT-WEIGHT: bold; COLOR: #008080; TEXT-ALIGN: left">Expected Result</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">12</TD><TD style="TEXT-ALIGN: right">01 02 18</TD><TD style="TEXT-ALIGN: right">03 04 05</TD><TD style="TEXT-ALIGN: right">06 10 14</TD><TD style="TEXT-ALIGN: right">07 12 17</TD><TD style="TEXT-ALIGN: right">08 13 15</TD><TD style="TEXT-ALIGN: right">09 11 16</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">19 20 21 </TD><TD>22 26 30</TD><TD>23 28 33</TD><TD>24 29 31</TD><TD>25 27 32</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">13</TD><TD style="TEXT-ALIGN: right">01 03 19</TD><TD style="TEXT-ALIGN: right">02 04 21</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">05 18 20 </TD><TD style="TEXT-ALIGN: right">06 16 29</TD><TD style="TEXT-ALIGN: right">07 11 15</TD><TD style="TEXT-ALIGN: right">08 10 33</TD><TD style="TEXT-ALIGN: right">09 28 30</TD><TD style="TEXT-ALIGN: right">12 14 25</TD><TD>13 22 32</TD><TD>17 24 26</TD><TD>23 27 31</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">14</TD><TD style="TEXT-ALIGN: right">01 04 20</TD><TD style="TEXT-ALIGN: right">02 05 19</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">03 18 21 </TD><TD style="TEXT-ALIGN: right">06 17 27</TD><TD style="TEXT-ALIGN: right">07 29 30</TD><TD style="TEXT-ALIGN: right">08 12 16</TD><TD style="TEXT-ALIGN: right">09 10 31</TD><TD style="TEXT-ALIGN: right">11 22 33</TD><TD>13 14 23</TD><TD>15 25 26</TD><TD>24 28 32</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">15</TD><TD style="TEXT-ALIGN: right">01 05 21</TD><TD style="TEXT-ALIGN: right">02 03 20</TD><TD style="FONT-WEIGHT: bold; COLOR: #666699; TEXT-ALIGN: left">04 18 19 </TD><TD style="TEXT-ALIGN: right">06 15 28</TD><TD style="TEXT-ALIGN: right">07 10 32</TD><TD style="TEXT-ALIGN: right">08 27 30</TD><TD style="TEXT-ALIGN: right">09 13 17</TD><TD style="TEXT-ALIGN: right">11 14 24</TD><TD style="TEXT-ALIGN: right">12 22 31</TD><TD>16 23 26</TD><TD>25 29 33</TD></TR></TBODY></TABLE>
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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