自定义订单排序

编程入门 行业动态 更新时间:2024-10-27 08:31:59
本文介绍了自定义订单排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想根据值(临界,高,中,低)对整个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.

更多推荐

自定义订单排序

本文发布于:2023-08-02 15:21:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1278862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   订单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!