0

我在 Excel 中有一个表格,它是通过数据库中的 Listobject 宏填充的。

我可以通过以下代码对表格进行排序:

'Sort on projecttabel
Dim lo As Excel.ListObject

Set lo = Plan.ListObjects(1)
With lo
.Sort.SortFields.Clear
    .Sort.SortFields.Add _
        Key:=Range("Table_appnlvd03_nkmgo_report_NKMGO_Report__KHNS_EFTTS_KPI32[klant]"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    .Sort.SortFields.Add _
        Key:=Range("Table_appnlvd03_nkmgo_report_NKMGO_Report__KHNS_EFTTS_KPI32[Status]"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    .Sort.SortFields.Add _
        Key:=Range("Table_appnlvd03_nkmgo_report_NKMGO_Report__KHNS_EFTTS_KPI32[RFO plandatum]"), SortOn:=xlSortOnValues, Order:=xlDescending, _
        DataOption:=xlSortNormal
    .Sort.SortFields.Add _
        Key:=Range("Table_appnlvd03_nkmgo_report_NKMGO_Report__KHNS_EFTTS_KPI32[Uitvoeren montage plan start]"), SortOn:=xlSortOnValues, Order:=xlDescending, _
        DataOption:=xlSortNormal

    With .Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End With

“状态”有多个整数值,范围从 1 到 100。我想做的是根据行的状态和另一列对行进行排序。我遇到的问题是每个状态的“第二列”排序是不同的。

我想要创建的是一个类似“Gant”的表格,其中不同的日期列按每个状态的降序排序。例如 (DD-MM-YYYY)

[Status]   [date1]              [date2]         [date3]
1         **10-01-2015**       12-02-2015        31-03-2015      
1         **09-01-2015**       14-02-2015        10-03-2015          
1         **08-01-2015**       06-02-2015        05-03-2015  
1         **07-01-2015**       18-02-2015        28-03-2015  
2         17-01-2015       **15-02-2015**        10-03-2015  
2         27-01-2015       **14-02-2015**        10-03-2015  
2         04-01-2015       **13-02-2015**        16-03-2015  
2         31-01-2015       **05-02-2015**        10-03-2015  
5         18-01-2015       12-02-2015        **30-03-2015**  
5         31-01-2015       18-02-2015        **27-03-2015**  
5         17-01-2015       04-02-2015        **26-03-2015**  
5         07-01-2015       27-02-2015        **08-03-2015**  
5         09-01-2015       24-02-2015        **03-03-2015**  

等等这可能吗?

4

1 回答 1

0

需要向表中添加一个工作字段,将其命名为“Sort.Key”,然后在该字段中输入此公式:

=CONCATENATE([@Status],CHAR(133),CHOOSE([@Status],[@date1],[@date2],,,[@date3]))

现在使用“Sort.Key”字段对表格进行排序

于 2015-09-28T12:55:25.123 回答