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
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
Post a Comment