本文介绍了自定义订单排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据值(临界,高,中,低)对整个C列进行排序.我正在启用宏的工作表上运行此代码
Hi I would like to sort the whole C column based on the values(Critical, high, medium,low). I am running this code on macro enabled worksheet
这是我的代码.
Sub run() Range("C:C").Sort Key1:=Range("C1"), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="Critical,High,Medium,Low", DataOption:=xlSortNormal End Sub它没有工作,因为指出了错误.没有争执.解决此问题的解决方案是什么?谢谢.
It did not work as there is error indicated. No argument. What is the solution to correct this problem? Thank you.
推荐答案您的自定义排序条件必须位于数组中.试试吧,
Your custom sort criteria needs to be in an array. Try,
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如果在公共模块中,则合格的父级工作表引用将有所帮助.
If this is in a public module, a qualified parent worksheet reference would help.
更多推荐
自定义订单排序
发布评论