Sub SortData()
With ActiveSheet
.SortFields.Clear
.Range("[B][COLOR=#ff0000]A2[/COLOR]:[COLOR=#000080]C[/COLOR][/B]" & .Rows.Count).Sort Key1:=.Range("[COLOR=#ff0000]A2[/COLOR]"), Order1:=[COLOR=#006400]xlAscending[/COLOR], Header:=xlNo
End With
End Sub
A | B | C | |
---|---|---|---|
1 | Date | Text1 | Text2 |
2 | 16/07/2019 | ABC_002 | XYZ_002 |
3 | ABC_003 | XYZ_003 | |
4 | 18/07/2019 | ABC_004 | XYZ_004 |
5 | 19/07/2019 | ABC_005 | XYZ_005 |
6 | ABC_006 | XYZ_006 | |
7 | 20/07/2019 | ABC_007 | XYZ_007 |
8 | 20/07/2019 | ABC_008 | XYZ_008 |
9 | ABC_009 | XYZ_009 | |
10 | 15/07/2019 | ABC_010 | XYZ_010 |
11 | 12/07/2019 | ABC_011 | XYZ_011 |
12 | ABC_012 | XYZ_012 | |
13 | 12/07/2019 | ABC_013 | XYZ_013 |
14 | 13/07/2019 | ABC_014 | XYZ_014 |
15 | ABC_015 | XYZ_015 | |
16 | 15/07/2019 | ABC_016 | XYZ_016 |
17 | ABC_017 | XYZ_017 | |
18 | 13/07/2019 | ABC_018 | XYZ_018 |
19 | ABC_019 | XYZ_019 | |
20 | 19/07/2019 | ABC_020 | XYZ_020 |
21 | ABC_021 | XYZ_021 |
Sheet: Sheet3 |
A | B | C | |
---|---|---|---|
1 | Date | Text1 | Text2 |
2 | 12/07/2019 | ABC_011 | XYZ_011 |
3 | 12/07/2019 | ABC_013 | XYZ_013 |
4 | 13/07/2019 | ABC_014 | XYZ_014 |
5 | 13/07/2019 | ABC_018 | XYZ_018 |
6 | 15/07/2019 | ABC_010 | XYZ_010 |
7 | 15/07/2019 | ABC_016 | XYZ_016 |
8 | 16/07/2019 | ABC_002 | XYZ_002 |
9 | 18/07/2019 | ABC_004 | XYZ_004 |
10 | 19/07/2019 | ABC_005 | XYZ_005 |
11 | 19/07/2019 | ABC_020 | XYZ_020 |
12 | 20/07/2019 | ABC_007 | XYZ_007 |
13 | 20/07/2019 | ABC_008 | XYZ_008 |
14 | ABC_003 | XYZ_003 | |
15 | ABC_006 | XYZ_006 | |
16 | ABC_009 | XYZ_009 | |
17 | ABC_012 | XYZ_012 | |
18 | ABC_015 | XYZ_015 | |
19 | ABC_017 | XYZ_017 | |
20 | ABC_019 | XYZ_019 | |
21 | ABC_021 | XYZ_021 |
Sheet: Sheet3 |
Try this method
Amend column range to match your data
Amend A2 to the first cell containing a data (or blank)
If required amend Order1:=xlDescending
Code:Sub SortData() With ActiveSheet .SortFields.Clear .Range("[B][COLOR=#ff0000]A2[/COLOR]:[COLOR=#000080]C[/COLOR][/B]" & .Rows.Count).Sort Key1:=.Range("[COLOR=#ff0000]A2[/COLOR]"), Order1:=[COLOR=#006400]xlAscending[/COLOR], Header:=xlNo End With End Sub