本文介绍了用宏对预定字段进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据五个参数对我的表进行排序。 我有以下列: 数据 Zeitraster Botschaftzahl Richtung LSB位置 Data
Zeitraster
Botschaftzahl
Richtung
LSB Position
- 名称发送
- 名称RX
- 数据
- Zeitraster
- Richtung
- Botschaftzahl
- LSB位置
- große
- Coef
- 最小
- 最大
按此顺序排序:
解决方案
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:
解决方案
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 SubThat 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.
更多推荐
用宏对预定字段进行排序
发布评论