Kalsefar Posted October 30, 2020 Share Posted October 30, 2020 Hello, I need VBA code to sort data automatically from largest to smallest or vice versa. 1 Quote Link to comment Share on other sites More sharing options...
Kalsefar Posted October 30, 2020 Author Share Posted October 30, 2020 6 hours ago, Kalsefar said: Hello, I need VBA code to sort data automatically from largest to smallest or vice versa. Private Sub Worksheet_Change(ByVal Target As Excel.Range) If Target.Column = 2 Then Dim lastrow As Long lastrow = Cells(Rows.Count, 2).End(xlUp).Row Range("B2:C" & lastrow).Sort key1:=Range("B2:B" & lastrow), order1:=xlAscending, Header:=xlNo End If End Sub This is the code if someone needs it in the future. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.