Auto sort data Automatically in excel | sort data automatically with formula and VBA code


 

Sort Data Automatically with formula and VBA code


VBA Code No. 1

VBA Code file No.1 Download Link - Clickhere

Private Sub Worksheet_Change(ByVal Target As Range)

Dim lastrow As Long

lastrow = Cells(Rows.Count, 2).End(xlUp).Row

    If Not Intersect(Target, Range("B:B")) Is Nothing Then

    Range("A1:B" & lastrow).Sort Key1:=Range("B1:B" & lastrow), order1:=xlAscending, Header:=xlNo

    End If

End Sub

VBA Code No. 2
VBA Code file No.2 Download Link - Clickhere

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim SalesTable As ListObject

Dim SortCol As Range

Set SalesTable = ActiveSheet.ListObjects("TableName")

Set SortCol = Range("TableName[Column Name]")

If Not Intersect(Target, SortCol) Is Nothing Then

    With SalesTable.Sort

    .SortFields.Clear

    .SortFields.Add Key:=SortCol, Order:=xlDescending

    .Header = xlYes

    .Apply

End With

End If

End Sub

कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

Microsoft Word top 180 keyboard shortcuts

Microsoft Word top 180 keyboard shortcuts Download shortcut keys File: MS Word File - Click here MS Excel File - Click here PDF File - Click...

Blogger द्वारा संचालित.