用宏对预定字段进行排序 [英] Sort predetermined fields with a macro
本文介绍了用宏对预定字段进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下列:
- 名称发送
- 名称RX
- 数据
- Zeitraster
- Richtung
- Botschaftzahl
- LSB位置
- große
- Coef
- 最小
- 最大
按此顺序排序:
- 数据
- Zeitraster
- Botschaftzahl
- Richtung
- LSB位置
解决方案
VBA只允许三个在任何一个进程中进行排序。如果需要三个以上的密钥,则先排序最后一个密钥,然后返回到三个最主要的密钥。
Sub custom_sort ()
Dim vKEYs As Variant
vKEYs = Array(Data,Zeitraster,Botschaftzahl,Richtung,LSB Position)
With ActiveSheet
With .Cells(1,1).CurrentRegion
.Cells.Sort Key1:=。列(Application.Match(vKEYs(3),.Rows(1),0)),Order1:= xlAscending,_
Key2:=。列(Application.Match(vKEYs(4),.Rows(1),0)),Order2:= xlAscending,_
方向:= xlTopToBottom,标题:= xlYes
.Cells.Sort Key1:=。列(Application.Match(vKEYs(0),.Rows(1),0)),Order1:= xlAscending,_
Key2:=。Columns(Application.Match(vKEYs (1),.Rows(1),0)),Order2:= xlAscending,_
Key3:=。列(Application.Match(vKEYs(2),.Rows(1),0)),Order3 := xlAscending,_
方向:= xlTopToBottom,标题:= xlYes
结束
结束
结束子
使用从A1开始的数据块。它使用标题行中的 application.Match
来获取每个排序键列的位置。
I would like to sort my table depending on five parameters. I have the following columns:
- Name TX
- Name RX
- Data
- Zeitraster
- Richtung
- Botschaftzahl
- LSB Position
- große
- Coef
- Min
- Max
Sorted in this order:
- Data
- Zeitraster
- Botschaftzahl
- Richtung
- LSB Position
解决方案
VBA will only allow three keys to sort on in any one process. If more than three keys are required, you sort the last keys first and then return to the three most primary keys.
Sub custom_sort()
Dim vKEYs As Variant
vKEYs = Array("Data", "Zeitraster", "Botschaftzahl", "Richtung", "LSB Position")
With ActiveSheet
With .Cells(1, 1).CurrentRegion
.Cells.Sort Key1:=.Columns(Application.Match(vKEYs(3), .Rows(1), 0)), Order1:=xlAscending, _
Key2:=.Columns(Application.Match(vKEYs(4), .Rows(1), 0)), Order2:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlYes
.Cells.Sort Key1:=.Columns(Application.Match(vKEYs(0), .Rows(1), 0)), Order1:=xlAscending, _
Key2:=.Columns(Application.Match(vKEYs(1), .Rows(1), 0)), Order2:=xlAscending, _
Key3:=.Columns(Application.Match(vKEYs(2), .Rows(1), 0)), Order3:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlYes
End With
End With
End Sub
That uses the data block starting in A1. It uses the application.Match
across the header row to get the position of each sort key column.
这篇关于用宏对预定字段进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文