Excel 1004 Runtime Error when Sorting Table

后端 未结 1 545
天涯浪人
天涯浪人 2021-01-17 03:03

Good Afternoon Stack Overflow Patrons:

I, like many others, are getting the dreaded 1004 Runtime Error when attempting to sort a table... but here is the kicker....

1条回答
  •  野的像风
    2021-01-17 03:38

    This worked for me:

    Sub Sort_Compiled_Data_Sheet()
    
         Dim sht as worksheet
    
         Set sht = ActiveWorkbook.Worksheets("Compiled_Data")
    
         sht.Activate
    
         With sht.ListObjects("Compiled_Data").Sort
    
            .SortFields.Clear
    
            .SortFields.Add Key:=Range("Compiled_Data[Date]"), SortOn:=xlSortOnValues, _
                             Order:=xlAscending
    
            .SortFields.Add Key:=Range("Compiled_Data[Contractor]"), _
                             SortOn:=xlSortOnValues, Order:=xlAscending
    
    
            .SortFields.Add Key:=Range("Compiled_Data[Customer]"), _
                                SortOn:=xlSortOnValues, Order:=xlAscending
    
            .SortFields.Add Key:=Range("Compiled_Data[Item]"), SortOn:=xlSortOnValues, _
                                Order:=xlAscending
    
    
             .Header = xlYes
             .MatchCase = False
             .Orientation = xlTopToBottom
             .SortMethod = xlPinYin
             .Apply
    
        End With
    
    End Sub
    

    0 讨论(0)
提交回复
热议问题