我想水平排序我的数据(字符串),但我想独立于其他行对每一行进行排序。
这样做的唯一方法是选择手动选择每一行并对其进行排序吗?
我根本不是VBA专家,我可以在c#或java中做到这一点,但我希望这个函数存在于excel中......
谢谢!
答案 0 :(得分:1)
这是VBA,假设您的最后一行在A列中有数据:
Sub Macro1()
Dim lLastRow As Long, lLoop As Long
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
'turn off updates to speed up code execution
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
For lLoop = 1 To lLastRow
Rows(lLoop).Sort key1:=Cells(lLoop, 1), order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlLeftToRight, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
Next
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With
End Sub