我必须在Excel中根据其值对单独的列进行排序。我制定了以下过程:
With calcCalculations
With .Sort
.SortFields.Add Key:=Range("BR2:BR5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("BV2:BV5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("CA2:CA5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("CD2:CD5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("BR:CD")
.Header = xlYes
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
End With
End with
该过程不会出错,但是不会对我的数据进行排序。我想念什么吗?
正如user3514930所说:您在.Apply
之前缺少End With
With calcCalculations
With .Sort
.SortFields.Add Key:=Range("BR2:BR5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("BV2:BV5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("CA2:CA5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("CD2:CD5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("BR:CD")
.Header = xlYes
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End with
正如其他用户所说。