VBA to sort Table that works in Excel 2010

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
272
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)
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,626
Office Version
  1. 365
Platform
  1. Windows
Change Add2 to Add
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,626
Office Version
  1. 365
Platform
  1. Windows
The Add2 only came into being with Xl 2016 & it's to deal with datatypes.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,764
Messages
5,626,733
Members
416,201
Latest member
brianhf

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
Top