How to sort Col A based on cell content; date-no date

mikecox39

Active Member
Joined
Mar 5, 2014
Messages
251
Office Version
  1. 365
Platform
  1. Windows
Column A in the Rows of my worksheet either contain a date or are empty.

I need a method that would sort the column the lists cells that contain dates and that contain no date.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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


Before

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]Date[/td][td]Text1[/td][td]Text2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]
16/07/2019​
[/td][td]ABC_002[/td][td]XYZ_002[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td][/td][td]ABC_003[/td][td]XYZ_003[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]
18/07/2019​
[/td][td]ABC_004[/td][td]XYZ_004[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]
19/07/2019​
[/td][td]ABC_005[/td][td]XYZ_005[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td][/td][td]ABC_006[/td][td]XYZ_006[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td]
20/07/2019​
[/td][td]ABC_007[/td][td]XYZ_007[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td]
20/07/2019​
[/td][td]ABC_008[/td][td]XYZ_008[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td][/td][td]ABC_009[/td][td]XYZ_009[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td]
15/07/2019​
[/td][td]ABC_010[/td][td]XYZ_010[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td]
12/07/2019​
[/td][td]ABC_011[/td][td]XYZ_011[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td][/td][td]ABC_012[/td][td]XYZ_012[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td]
12/07/2019​
[/td][td]ABC_013[/td][td]XYZ_013[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td]
13/07/2019​
[/td][td]ABC_014[/td][td]XYZ_014[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td][/td][td]ABC_015[/td][td]XYZ_015[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
16
[/td][td]
15/07/2019​
[/td][td]ABC_016[/td][td]XYZ_016[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
17
[/td][td][/td][td]ABC_017[/td][td]XYZ_017[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
18
[/td][td]
13/07/2019​
[/td][td]ABC_018[/td][td]XYZ_018[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
19
[/td][td][/td][td]ABC_019[/td][td]XYZ_019[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
20
[/td][td]
19/07/2019​
[/td][td]ABC_020[/td][td]XYZ_020[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
21
[/td][td][/td][td]ABC_021[/td][td]XYZ_021[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet3[/td][/tr][/table]

After

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]Date[/td][td]Text1[/td][td]Text2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]
12/07/2019​
[/td][td]ABC_011[/td][td]XYZ_011[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]
12/07/2019​
[/td][td]ABC_013[/td][td]XYZ_013[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]
13/07/2019​
[/td][td]ABC_014[/td][td]XYZ_014[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]
13/07/2019​
[/td][td]ABC_018[/td][td]XYZ_018[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]
15/07/2019​
[/td][td]ABC_010[/td][td]XYZ_010[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td]
15/07/2019​
[/td][td]ABC_016[/td][td]XYZ_016[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td]
16/07/2019​
[/td][td]ABC_002[/td][td]XYZ_002[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td]
18/07/2019​
[/td][td]ABC_004[/td][td]XYZ_004[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td]
19/07/2019​
[/td][td]ABC_005[/td][td]XYZ_005[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td]
19/07/2019​
[/td][td]ABC_020[/td][td]XYZ_020[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td]
20/07/2019​
[/td][td]ABC_007[/td][td]XYZ_007[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td]
20/07/2019​
[/td][td]ABC_008[/td][td]XYZ_008[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td][/td][td]ABC_003[/td][td]XYZ_003[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td][/td][td]ABC_006[/td][td]XYZ_006[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
16
[/td][td][/td][td]ABC_009[/td][td]XYZ_009[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
17
[/td][td][/td][td]ABC_012[/td][td]XYZ_012[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
18
[/td][td][/td][td]ABC_015[/td][td]XYZ_015[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
19
[/td][td][/td][td]ABC_017[/td][td]XYZ_017[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
20
[/td][td][/td][td]ABC_019[/td][td]XYZ_019[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
21
[/td][td][/td][td]ABC_021[/td][td]XYZ_021[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet3[/td][/tr][/table]
 
Last edited:
Upvote 0
Avoiding VBA

If data is contiguous...
- apply Data Filter (see Data Tab) to your range
- click on down arrow in column A
- click on Sort Oldest to Newest \ Newest to Oldest
 
Last edited:
Upvote 0
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

Perfect! Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,225,739
Messages
6,186,746
Members
453,370
Latest member
juliewar

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