Auto Sort Multicolumn after new data enter

h434

New Member
Joined
Apr 27, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
How to auto sort column for Column J first after new data key in even column M not fill up yet?

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("J:J, M:M")) Is Nothing Then
If Target.CountLarge > 1 Then Exit Sub
If Range("J" & Target.Row) <> "" And Range("M" & Target.Row) <> "" Then
Range("J1:M" & Range("J" & Rows.Count).End(1).Row).Sort _
key1:=Range("J1"), order1:=xlAscending, key2:=Range("M1"), order2:=xlAscending, Header:=xlYes
End If
End If
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
this code trigger any change in either J or M
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("J:J, M:M")) Is Nothing Then
    Range("J1:M" & Range("J" & Rows.Count).End(1).Row).Sort _
    key1:=Range("J1"), order1:=xlAscending, key2:=Range("M1"), order2:=xlAscending, Header:=xlYes
End If
End Sub
 
Upvote 0
Solution
If i want to make change in column J first without data entry at column M, how to do it. after sorting at J, then when I enter data at column M, it continue to sort at column M then
 
Upvote 0
This is how my code work:
1- Change J (or M)
2- Sorting J and M
Is it OK?
If not, which step do you need?
 
Upvote 0
It works!!! Thank a lot, this one solve my problem. Thank you yaa;)
 
Upvote 0

Forum statistics

Threads
1,214,849
Messages
6,121,925
Members
449,056
Latest member
denissimo

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