我的电子表格中有多个带有标题的列,我将随着时间的推移添加到每个列,但数量不同。这些列将彼此独立并以不同的速率增长。
我知道如何按当前区域对所有内容进行排序,但这似乎只允许基于一个标头进行排序。为了简单起见,您将如何按字母顺序同时对两列并排排序?
尝试了类似的方法,但它无法运行:
Sub Alphabatize()
' Alphabatize Macro
Dim LastRowA As Long
Dim LastRowB As Long
'Determine Last Row
LastRowA = Range("A1" & Rows.Count).End(xlUp).Row
LastRowB = Range("B1" & Rows.Count).End(xlUp).Row
'Sort
With Range("A1")
.SetRange Range("A1:LastRowA")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Range("B1")
.SetRange Range("B1:LastRowB")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
请尝试下一个方法。但
simultaneity
的概念有点不同。它们在同一段代码中排序,但连续......:
Sub sortTwoIndependentColumns()
With ActiveWorkbook
With ActiveSheet
If .AutoFilterMode Then .AutoFilterMode = False
With .Columns("A:A")
.cells.Sort key1:=.Columns(1), Order1:=xlAscending, _
Orientation:=xlTopToBottom, header:=xlYes
End With
With .Columns("B:B")
.cells.Sort key1:=.Columns(1), Order1:=xlAscending, _
Orientation:=xlTopToBottom, header:=xlYes
End With
End With
End With
End Sub