• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sort tables in other sheet with VBA

martinpaiva

New Member
Hi All,


I have the follwing code to sort two tables. This code works when its executed in the sheet where the tables are stored. But I want to move this code to another sheet and execute it when that sheet is selected.


For some reason i get the folliwing error: "Application-defined or object-defined error"


'

Sheets("Source Data").Select

ActiveWorkbook.Worksheets("Source Data").ListObjects("EMPLEADOSSWISSGUARD"). _

Sort.SortFields.Clear

ActiveWorkbook.Worksheets("Source Data").ListObjects("EMPLEADOSSWISSGUARD"). _

Sort.SortFields.Add Key:=Range( _

"EMPLEADOSSWISSGUARD[[#All],[EMPLEADOS SWISSGUARD]]"), SortOn:=xlSortOnValues _

, Order:=xlAscending, DataOption:=xlSortNormal

With ActiveWorkbook.Worksheets("Source Data").ListObjects("EMPLEADOSSWISSGUARD" _

).Sort

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With

ActiveWorkbook.Worksheets("Source Data").ListObjects("Table1").Sort.SortFields. _

Clear

ActiveWorkbook.Worksheets("Source Data").ListObjects("Table1").Sort.SortFields. _

Add Key:=Range("Table1[[#All],[EMPLEADOS CLEANWARD]]"), SortOn:= _

xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With ActiveWorkbook.Worksheets("Source Data").ListObjects("Table1").Sort

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With

'
 
Back
Top