Auto sort after date stamp

HDavidson

New Member
Joined
Sep 23, 2018
Messages
17
I am using the Vba code below to apply a date stamp in a spreadsheet .How can i adapt this to auto sort all the data with newest entry at the top.The spreadsheet covers the columns A to J inclusive


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row > 1 Then Cells(Target.Row, "j") = Now()
End Sub


Thanks
 
well i thought it was ??.When i enter any data the last entry does not go to the top of the list ie row 2 it only moves up to the row below the previous entry.If you follow this through and keep adding data it means the latest entry would be the last and not the first as i needed.Hope you can assist.


Thanks
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Re,

Is the following macro ... in line with your expectations ...?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Count > 1 Then Exit Sub
   Dim last As Long
   Application.ScreenUpdating = False
   Application.EnableEvents = False
   If Target.Row > 1 Then Cells(Target.Row, "J") = Now()
   last = ActiveSheet.Cells(Application.Rows.Count, "J").End(xlUp).Row
   Range("A1:J" & last).Sort [J1], xlDescending, Header:=xlYes
   Application.EnableEvents = True
   Application.ScreenUpdating = True
End Sub

HTH
 
Last edited:
Upvote 0
Super job James your a star.Thanks again for all you help how easy would it be to add columns if i extended the spreadsheet.
 
Upvote 0
Glad it is now all working as expected ... :)

Should you extend your spreadsheet :

the only thing to do would to adjust the Column Letter J in Red ...to whatever new final column you might have

Range("A1:J" & last).Sort [J1], xlDescending, Header:=xlYes

All the rest has to remain as is ...

Hope this clarifies ...
 
Upvote 0
what if i add a column before column a that i dont want to be included in the sort would i just change a1 to b1.


Thanks
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,525
Members
449,037
Latest member
tmmotairi

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