Ant*_*ton 0 excel vba excel-vba
我正在尝试对选择中的每一行进行排序.例:
排序前:
8 3 17
2 9 4
5 3 8
Run Code Online (Sandbox Code Playgroud)
排序后:
3 8 17
2 4 9
3 5 8
Run Code Online (Sandbox Code Playgroud)
我写了这段代码,但它不起作用:
Public Sub SortByString()
Dim row As Range
For Each row In Selection.Rows
row.Sort Key1:=row, Order1:=xlAscending, Orientation:=xlSortColumns
Next row
End Sub
Run Code Online (Sandbox Code Playgroud)
我是VBA的新手.比我做错了?请帮忙.
问题在于您的Orientation参数.它应该是xlSortRows或xlLeftToRight:
row.Sort Key1:=row, Order1:=xlAscending, Orientation:=xlSortRows
Run Code Online (Sandbox Code Playgroud)
要么
row.Sort Key1:=row, Order1:=xlAscending, Orientation:=xlLeftToRight
Run Code Online (Sandbox Code Playgroud)
第一个是有道理的,因为你实际上是排序行.第二个是我用宏录像机得到的.