选择给定范围内的n行块并按降序排序 - VBA Excel

问题描述 投票:0回答:1

我正在学习excel中VBA编码的基础知识。我试图创建一个VBA代码来选择一个范围内的“n”(给定数量的行)块,然后对从最高到最低的数字中选择的这些行进行排序。请参阅下面的示例。有任何想法吗?。预先感谢。

期望的范围。

enter image description here

选定的块

enter image description here

期望的排序

enter image description here

excel vba
1个回答
1
投票

尝试解决这个问题。

sub meh()
    dim i as long, rws as long

    rws=4

    with worksheets(1)
        for i=rws+1 to .cells(.rows.count, "A").end(xlup).row step rws *2
            with .cells(i, "A").resize(rws, 1)
                .Sort Key1:=.cells(1), Order1:=xldescending, _
                      Orientation:=xlTopToBottom, Header:=xlNo
            end with
        next i
    end with

end sub
© www.soinside.com 2019 - 2024. All rights reserved.