VBA Code:
Sub AutoSort2()
'
' AutoSort Macro
' This will sort by the list of topics
'
Dim dynlist As Variant
dynlist = Application.Transpose(Sheet2.ListObjects("table2").ListColumns(2).DataBodyRange)
ActiveTable = ActiveSheet.Range("b15").ListObject.Name
ActiveSheet.ListObjects(ActiveTable).Sort.SortFields.Clear
Application.AddCustomList listarray:=dynlist
ActiveSheet.ListObjects(ActiveTable).Sort.SortFields. _
Add2 Key:=ActiveSheet.ListObjects(ActiveTable).ListColumns(7).DataBodyRange, SortOn:=xlSortOnValues, Order:=xlAscending, _
CustomOrder:=Application.CustomListCount, _
DataOption:=xlSortNormal
With ActiveSheet.ListObjects(ActiveTable).Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.DeleteCustomList Application.CustomListCount
ActiveSheet.Calculate
Sheet2.Calculate
Sheet5.Calculate
Sheet6.Calculate
End Sub
First off, I'm seriously noob at VBA, I just google stuff and put various solutions together to achieve what I want.
I just got off microsoft support which help pin-point that the VBA is the issue. Because when I try to manually sort, nothing goes wrong. But if I should use the macro, then try to save afterwards, Excel would crash.
Somebody save me pls. Thanks
Last edited by a moderator: