How could I auto sort column 9 (descending) automatically upon any cell update

diogodasilva

New Member
Joined
Feb 17, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
With the help of @Fluff who finessed the code to update column 9 with a timestamp if any columns (1 to 17, except 9) is edited. and second part of the code reorganizes descending based on the timestamp (column 9).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   Select Case Target.Column
      Case 1 To 8, 10 To 17
         Range("I" & Target.Row).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
   End Select
End Sub

Now I am trying to implement auto sort column 9 (descending) automatically upon update but it is beyond my knowledge . So the table reorganizes by last update automatically.
Thanks in advance
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Assuming your column 9 has a header

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   Application.EnableEvents = False
   Select Case Target.Column
      Case 1 To 8, 10 To 17
        With Range("I1", Range("I" & Rows.Count).End(xlUp))
           .Item(Target.Row, 1).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
           .Resize(IIf(Target.Row > .Rows.Count, Target.Row, .Rows.Count)).Sort Range("I2"), 2, , , , , , 1
        End With
   End Select
   Application.EnableEvents = True
End Sub
 
Upvote 0
Assuming your column 9 has a header

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   Application.EnableEvents = False
   Select Case Target.Column
      Case 1 To 8, 10 To 17
        With Range("I1", Range("I" & Rows.Count).End(xlUp))
           .Item(Target.Row, 1).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
           .Resize(IIf(Target.Row > .Rows.Count, Target.Row, .Rows.Count)).Sort Range("I2"), 2, , , , , , 1
        End With
   End Select
   Application.EnableEvents = True
End Sub
Headers are on row 3.
1646768972113.png
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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