VBA to sort Table that works in Excel 2010

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
439
Office Version
  1. 365
Platform
  1. Windows
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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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