Date format with sorting

shimaa01234

Active Member
Joined
Jun 24, 2014
Messages
446
Can you format, this date dd/ mm/yyyy & The sort of small to large, in one formula
08/05/2014
08/06/2014
08/07/2014
08/10/2014
08/11/2014
08/12/2014
08/13/2014
08/18/2014
08/19/2014
08/20/2014
08/03/2014
08/04/2014
08/06/2014
08/13/2014
08/19/2014
08/20/2014

<colgroup><col></colgroup><tbody>
</tbody>
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
Sub FormatAndSort()
    Columns([COLOR=#ff0000]"A:A"[/COLOR]).Select
    Selection.NumberFormat = "dd/mm/yyyy"
    ActiveWorkbook.Worksheets("[COLOR=#ff0000]Sheet1[/COLOR]").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("[COLOR=#ff0000]Sheet1[/COLOR]").Sort.SortFields.Add Key:=Range([COLOR=#ff0000]"A1"[/COLOR]), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets([COLOR=#ff0000]"Sheet1"[/COLOR]).Sort
         .SetRange Range([COLOR=#ff0000]"a1"[/COLOR]).Resize(Cells(Rows.Count, 1).End(xlUp).Row, [COLOR=#ff0000]1[/COLOR])  
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub


This would be the one you should use then.

If this gives you the wrong sort, it might be because some of your dates have different EU/US formats, I know this is an issue for some people. Atleast for me with an European version. There are some difficulties there.

if you look at what the cell contains (you select it and look at the value, and not its format) what does it say. "08/18/2014" or "08.18.2014" ?

Let me know how this works, should not return an error now atleast, you still had some "H" column in the code you sent me that contained an error.
 
Last edited:
Upvote 0
And I can assume its the same line giving the error? (Your worksheet might have something i column 1 I am not aware. (headers are accounted for, but something else I do not know about?) I just paste the data you posted in col"A", and run it.

First off tho, can you do the job manually? I mean, do what you want, just the slow way, and it works?

If that is the case, why not just record what you are doing, and when selecting ranges(areas in the spreadsheet) use "ctrl+shift+arrowkeys" to do so.

Or are you not able to get it done manually?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,215
Messages
6,123,668
Members
449,114
Latest member
aides

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