Excel SortFields添加然后排序 [英] Excel SortFields add then sort

查看:839
本文介绍了Excel SortFields添加然后排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮助我理解以下摘要吗?

Would you help me understand this snippset:

首先,似乎在

MainSheet.Sort.SortFields.Clear
For lI = 1 To vSortKeys(0, 1)   
    MainSheet.Sort.SortFields.Add Key:=Range(vSortKeys(lI, 1) & 2), 
       SortOn:=xlSortOnValues, Order:=vSortKeys(lI, 2), DataOption:=xlSortNormal
Next

然后,我了解以下代码有效地运行了排序

Then, I understand that the following code is effectively running the sort

With MainSheet.Sort
    .SetRange Range("A" & lFrom & ":" & GEN_REV_END & lTo)
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With

此解释是否正确-需要首先添加排序规则,然后将其与第二部分一起应用?

Is this interpretation correct - need to add a sorting rule first, then apply it with the second part ?

然后,为什么要在第二部分的

Then, why are we defining a range for sort in the second part, in

With MainSheet.Sort
    .SetRange Range("A" & lFrom & ":" & GEN_REV_END & lTo)

End With

是否不是我们为Key:=Range(vSortKeys(lI, 1) & 2)排序的规则?排序有效地在哪个单元格范围内进行?

Is it not already in the rule that we sort for Key:=Range(vSortKeys(lI, 1) & 2) ? On which range of cells is the sort effectively run ?

推荐答案

正在将排序应用于Sort.SetRange中指定的范围. Sort.SortFields.Add中的Key参数允许您指定将确定配音顺序的字段.每个字段可以只是具有列标题的单元格.您可以为多个排序级别添加多个键.

The sorting is being applied to the range specified in Sort.SetRange. The Key parameter in Sort.SortFields.Add allows you to specify fields that will determine the order of soring. Each field can be just the cell with the column header. You can add multiple keys for several sorting levels.

举个例子,如果您在单元格A1:C10中有数据,并且想要以升序的方式对其进行排序,以列A中的信息为排序键,则可以执行此操作以在列中设置数据A作为键:

To give an example, if you have data in cells A1:C10 and you want to sort it in an ascending manner, taking information in column A as the key for sorting, you can do this to set data in column A as the key:

MainSheet.Sort.SortFields.Add Key:=Range("A1") '("A1:A10") will also work

然后您可以指定将基于该键排序的范围,如下所示:

And then you can specify the range that will be sorted based on that key as follows:

 MainSheet.Sort.SetRange Range("A1:C10")

这篇关于Excel SortFields添加然后排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆