Share via

VBA Table Sort Error

Anonymous
2016-04-12T11:43:43+00:00

Hello,

I'm trying to get a table that I created and named in my VBA code to sort alphabetically. However when the code reaches the point to call out the range and define the sort parameters (emboldened in the code), it keeps popping up with error code 400. I'm not sure what the issue is, in part because I used a similar chunk of code in macro that works perfectly fine. Any help would be appreciated.

    Dim itemtable As Excel.ListObject

    ActiveSheet.UsedRange.Select

    Set itemtable = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)

    itemtable.Name = "Itemized_Parts_Table"

    With itemtable.Sort

        .SortFields.Clear

        'Issue is here'

        .SortFields.Add Key:=Range("Itemized_Parts_Table[Level 1 Install]"), _

SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

        .Header = xlYes

        .MatchCase = False

        .Orientation = xlTopToBottom

        .SortMethod = xlPinYin

        .Apply

    End With

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2016-04-13T16:56:09+00:00

    Unfortunately that didn't work either... I'm not sure why, but the .Add part of the sort code just refuses to work no matter what sort parameters I give it. I've found another way to do the task that the sort was meant to help with so it's not necessary for the sorting to be done, thanks again for the help! :)

    Was this answer helpful?

    0 comments No comments