第2行从左到右的排序范围

时间:2019-08-22 04:16:48

标签: excel vba sorting

我在excel中有3行,我想从VBA第2行的最小值到最大值按从左到右的顺序排序。

我发现如何根据第一行进行操作:

Range(Rows(1),Rows(3)).Sort Key1:=Range(Rows(1),Rows(3)), Order1:=xlAscending, Orientation:=xlLeftToRight

这就是我拥有的:
5,6,2,1
4、3、2、1
a,d,w,x

这就是我想要的:
1,2,6,5
1,2,3,4
x,w,d,a

有什么主意,我需要在我所拥有的内容中添加几行代码才能使其正常工作?

1 个答案:

答案 0 :(得分:1)

Key1:=Range(Rows(1),Rows(3))更改为Key1:=Rows(2)

尝试:

Range(Rows(1), Rows(3)).Sort Key1:=Rows(2), Order1:=xlAscending, Orientation:=xlLeftToRight

演示:

enter image description here

相关问题