gpt4 book ai didi

excel - 自定义订单排序

转载 作者:行者123 更新时间:2023-12-04 22:31:00 25 4
gpt4 key购买 nike

嗨,我想根据值(关键、高、中、低)对整个 C 列进行排序。我在启用宏的工作表上运行此代码

这是我的代码。

Sub run()
Range("C:C").Sort Key1:=Range("C1"), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="Critical,High,Medium,Low", DataOption:=xlSortNormal
End Sub

它没有工作,因为有错误指示。没有争论。纠正这个问题的解决方案是什么?谢谢你。

最佳答案

您的自定义排序标准需要在一个数组中。尝试,

Sub runSortC()
Dim vCustom_Sort As Variant, rr As Long

vCustom_Sort = Array("Critical","High","Medium","Low", Chr(42))
Application.AddCustomList ListArray:=vCustom_Sort

with Range("C:C")
.parent.Sort.SortFields.Clear

'sort on custom order with header
.Cells.Sort Key1:=.Columns(1), Order1:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlYes, MatchCase:=False, _
OrderCustom:=Application.CustomListCount + 1

.parent.Sort.SortFields.Clear

End With

End Sub

如果这是在公共(public)模块中,合格的父工作表引用会有所帮助。

关于excel - 自定义订单排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52848753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com