Sort groups of cells into numerical order

jock444

New Member
Joined
Feb 13, 2019
Messages
9
Hi, I would appreciate any help on how to write some code to sort groups of cells I have into numerical order. The cells are grouped like this:

[TABLE="class: outer_border, width: 200"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]16[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD="align: center"]green[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD="align: center"]triangle[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD="align: center"]blue[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD="align: center"]square[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]21[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD="align: center"]yellow[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD="align: center"]diamond[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD="align: center"]red[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD="align: center"]circle[/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]


The numbers are start and end times so I would like to sort the cells by the first number in each group (cells A1, A5, A9, A13 in my example) so the result should be this:

[TABLE="class: outer_border, width: 200"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD="align: center"]red[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD="align: center"]circle[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD="align: center"]blue[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD="align: center"]square[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]16[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD="align: center"]green[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD="align: center"]triangle[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]21[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD="align: center"]yellow[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD="align: center"]diamond[/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]


I'm new to coding so really not sure the best way of doing it. The groups of cells are all named ranges if that makes it simpler? Many thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It can be with a formula and ordering the table.
For example, create an Auxiliary column and write the formula in C2 as shown in the following example, then copy down.


Book1
ABC
1DATA 1DATA 2AUX
2151615
3green15
4triangle15
515
6111211
7blue11
8square11
911
10202120
11yellow20
12diamond20
1320
14787
15red7
16circle7
Hoja4
Cell Formulas
RangeFormula
C2=IF(ISNUMBER(A2),A2,C1)


Now sort the table by the auxiliary column from lowest to highest


Book1
ABC
1DATA 1DATA 2AUX
2787
3red7
4circle7
5111211
6blue11
7square11
811
9151615
10green15
11triangle15
1215
13202120
14yellow20
15diamond20
1620
Hoja4
 
Upvote 0
Thanks Dante, that's a simple solution which should work well for what I need. Appreciate your help again :).
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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