Macro para ordenar automáticamente de manera ascendente o descendente un tabla en base a un determinada columna

Código

Private Sub Worksheet_Change(ByVal Target As Range)
Dim w As Worksheet, t As ListObject, c As ListColumn

Set w = ThisWorkbook.Worksheets("")
Set t = w.ListObjects("")
Set c = t.ListColumns("")

If Not Intersect(Target, c.DataBodyRange) Is Nothing Then
With t.Sort
.SortFields.Clear
.SortFields.Add2 Key:=c.DataBodyRange, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
t.ShowAutoFilter = False
End If
End Sub

Comentarios