VBA to sort Table that works in Excel 2010

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
435
Office Version
  1. 365
  2. 2010
Hello

I've got some code below attached to a button that works in Excel 365 to sort a Table, which throws up Error 438 when running in Excel 2010

Is there something I can modify so that it run on Excel 2010?

VBA Code:
Sub SortEventsByDate()
    Sheets("Events").Select
    ActiveSheet.Unprotect Password:="password"
    ActiveWorkbook.Worksheets("Events").ListObjects("tbl_Events").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("Events").ListObjects("tbl_Events").Sort.SortFields. _
        Add2 Key:=Range("tbl_Events[[#All],[Event Date]]"), SortOn:=xlSortOnValues _
        , Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Events").ListObjects("tbl_Events").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Sheets("Events").Select
    ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowSorting:=True, AllowFormattingCells:=False, AllowFormattingColumns:=False, AllowFormattingRows:=False, AllowInsertingColumns:=False, AllowDeletingColumns:=False
End Sub

(As you might be able to tell, I can't write VBA from scratch,, but am trying to to learn how to edit recorded macros! Any help greatly appreciated)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Change Add2 to Add
 
Upvote 0
Solution
The Add2 only came into being with Xl 2016 & it's to deal with datatypes.
 
Upvote 0

Forum statistics

Threads
1,213,483
Messages
6,113,919
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top