• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sorting Table By Date with Macro

Tech56

Member
Hello,

Does anyone know of code to sort a table column by oldest to newest date? This is on the Transactions sheet column B.

It will need to call the unprotect module in order to do the sort I think.

Code:
Sub SortDates()
Call Unprotect_Transactions
'Code to sort B19:B1000 oldest to newest dates please.


Call Protect_Transactions
End Sub
 

Attachments

  • Money Manager 20.1 Sort Trial.xlsm
    294.6 KB · Views: 1
I am sorry but I found a solution:

Code:
Sub SortDates()
    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim rng As Range
Call Unprotect_Transactions
    
    Set ws = ActiveSheet
    Set tbl = ws.ListObjects("Table1")
    Set rng = Range("Table1[Date]")
    
    With tbl.Sort
       .SortFields.Clear
       .SortFields.Add Key:=rng, SortOn:=xlSortOnValues, Order:=xlAscending
       .Header = xlYes
       .Apply
    End With
Call Protect_Transactions
End Sub
 
Back
Top