Jump to content

Largest to smallest or vice versa


Kalsefar
 Share

Recommended Posts

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.

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...