如何在Excel中重新排列两列中的值,使它们相对于彼此始终按给定的(例如:字母)顺序排列



长期潜伏者,感谢您的帮助!

这是我在Excel中的问题:有没有一个公式(或其他方法)可以让我把数据分为两列,然后重新排列,使每一行的值相对于彼此总是按相同的顺序排列(按字母顺序排列也可以)?

下面是我的数据的一个例子:

位置1 nbsp nbsp nbsp 位置2

C街 nbsp nbsp nbsp nbsp nbsp Z街

C街 nbsp nbsp nbsp nbsp nbsp Z街

Z街 nbsp nbsp nbsp nbsp nbsp C街

Z街 nbsp nbsp nbsp nbsp nbsp C街

以及我希望这些行看起来如何:

位置1 nbsp nbsp nbsp 位置2

C街 nbsp nbsp nbsp nbsp nbsp Z街

C街 nbsp nbsp nbsp nbsp nbsp Z街

C街 nbsp nbsp nbsp nbsp nbsp Z街

C街 nbsp nbsp nbsp nbsp nbsp Z街

我希望这个问题在其他地方还没有得到回答。非常感谢。

你试过这个代码吗?

Sub Macro1()
Dim lLastRow As Long, lLoop As Long
lLastRow = ActiveSheet.UsedRange.Rows.Count + 1
Application.ScreenUpdating = False
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
Application.ScreenUpdating = True
End Sub

最新更新