VBA Autosort table by date

mland1027

New Member
Joined
Apr 13, 2018
Messages
4
Hello!
I am looking for a way or VBA code(Unsure of what would work better) that would automatically sort the data coming into a table by current date to oldest date. Below is how i have my table set up, so ideally the table would automatically sort by column B once the data is inputted
Column a b c
Unit TypeMove In Date Rent Amount
3x3sw-d06/26/20163,010.00
2x2sw-bu09/01/20152,345.00
2x2sw-f10/30/20162,660.00
2x2sw-g06/05/20142,470.00
2x2sw-c06/01/20122,325.00

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

Any suggestions greatly appreciated

thanks!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
i am running a report and inputting that report into another tab within the workbook. the table is then pulling from that report.

thank you
 
Upvote 0
Place this in the Workbook Event

Code:
Option Explicit




Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
Range("A1").CurrentRegion.Sort Range("B1"), xlAscending, , , , , , xlYes
End Sub
 
Upvote 0
Thank you, but when i run the code i get a macros window to select the project location for the macros
 
Upvote 0
I don't understand your response. Did you put the code in the Workbook Event or just in a module?

With the VBE open, click on ThisWorkbook and then insert the code. It is Workbook Event and not a normal VBA module.
 
Upvote 0
Merged cells are a disaster when it comes to Excel and VBA. VBA does not work well with merged cells. Smart Excel developers avoid using merged cells. In my opinion, they cause more issues than they are worth. I avoid using merged cells especially when working with VBA.
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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