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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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
A
B
C
1
DateText1Text2
2
16/07/2019​
ABC_002XYZ_002
3
ABC_003XYZ_003
4
18/07/2019​
ABC_004XYZ_004
5
19/07/2019​
ABC_005XYZ_005
6
ABC_006XYZ_006
7
20/07/2019​
ABC_007XYZ_007
8
20/07/2019​
ABC_008XYZ_008
9
ABC_009XYZ_009
10
15/07/2019​
ABC_010XYZ_010
11
12/07/2019​
ABC_011XYZ_011
12
ABC_012XYZ_012
13
12/07/2019​
ABC_013XYZ_013
14
13/07/2019​
ABC_014XYZ_014
15
ABC_015XYZ_015
16
15/07/2019​
ABC_016XYZ_016
17
ABC_017XYZ_017
18
13/07/2019​
ABC_018XYZ_018
19
ABC_019XYZ_019
20
19/07/2019​
ABC_020XYZ_020
21
ABC_021XYZ_021
Sheet: Sheet3

After

Excel 2016 (Windows) 32 bit
A
B
C
1
DateText1Text2
2
12/07/2019​
ABC_011XYZ_011
3
12/07/2019​
ABC_013XYZ_013
4
13/07/2019​
ABC_014XYZ_014
5
13/07/2019​
ABC_018XYZ_018
6
15/07/2019​
ABC_010XYZ_010
7
15/07/2019​
ABC_016XYZ_016
8
16/07/2019​
ABC_002XYZ_002
9
18/07/2019​
ABC_004XYZ_004
10
19/07/2019​
ABC_005XYZ_005
11
19/07/2019​
ABC_020XYZ_020
12
20/07/2019​
ABC_007XYZ_007
13
20/07/2019​
ABC_008XYZ_008
14
ABC_003XYZ_003
15
ABC_006XYZ_006
16
ABC_009XYZ_009
17
ABC_012XYZ_012
18
ABC_015XYZ_015
19
ABC_017XYZ_017
20
ABC_019XYZ_019
21
ABC_021XYZ_021
Sheet: Sheet3
 
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,213,497
Messages
6,114,002
Members
448,543
Latest member
MartinLarkin

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