用宏对预定字段进行排序

编程入门 行业动态 更新时间:2024-10-23 12:36:56
本文介绍了用宏对预定字段进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想根据五个参数对我的表进行排序。 我有以下列:

  • 名称发送
  • 名称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.

    更多推荐

    用宏对预定字段进行排序

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

    发布评论

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

    >www.elefans.com

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