sorting by date

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a procedure to transfer some data from a table in one workbook to a table in another workbook. I want to be able to sort everything in the destination table by date in ascending order after the transfer but I am not sure of the vba code.

The date is in column A of both workbooks
The table where the data is going to be transferred to is called tblCosting
The workbook that contains tblCosting is called "costing tool.xlsm"

I think that is everything, let me know if I have forgot something.

Thanks,
Dave
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
This will only work if the workbook has already been saved under that name BEFORE this macro is run

Amend to correct sheet name or if it is the first sheet in workbook ...
Code:
  Set Tbl = Workbooks("Costing Tool.xlsm").Sheets([COLOR=#ff0000]1[/COLOR]).ListObjects("tblCosting")

Code:
Sub Sort()
    Dim Tbl As ListObject, Col As Range
    
    Set [COLOR=#006400]Tbl[/COLOR] = Workbooks("Costing Tool.xlsm").Sheets("[I][COLOR=#ff0000]SheetName[/COLOR][/I]").ListObjects("tblCosting")
    Set [COLOR=#006400]Col[/COLOR] = Tbl.ListColumns(1).Range
    
    With [COLOR=#006400]Tbl[/COLOR].Sort
       .SortFields.Clear
       .SortFields.Add Key:=[COLOR=#006400]Col[/COLOR], SortOn:=xlSortOnValues, Order:=xlAscending
       .Header = xlYes
       .Apply
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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