假设在表格的B列中,我按行排列以下数据:
New York zip- 2067 . Temperature cool
Beijing zip- 1063 . Temperature is chilly
Africa zip- 3069 . Temperature is hot
等等
我想按照zip值的顺序对列进行排序。 所以在这种情况下它将是:
Beijing zip- 1063 . Temperature is hot
New York .......
依此类推至第n行......
如何做到这一点。有什么办法/公式吗?
答案 0 :(得分:0)
如果可以&将在VBA中编码,您可以执行以下操作:
.
和zip-
之间进行部分。如果您将值放在A1:A3
中,它将是这样的:
Public Sub TestMe()
Dim readDataArr As Variant
Dim testArr As Variant
Dim cnt As Long
Dim myCell As Range
Dim addSomething As String
Dim separator As String
separator = "SomethingQuiteUniqe"
For Each myCell In Range("A1:A3")
'Read the every cell of the range and take the part between . and the zip-.
addSomething = Split(Split(myCell, "zip-")(1), ".")(0)
'Then put this part at the beginning of the range.
myCell = addSomething & separator & myCell
Next myCell
'Sort the range, which would be sorted by the number
Range("A1:A3").Sort key1:=Range("A1:A3")
'Remove the numeric part
For Each myCell In Range("A1:A3")
myCell = Split(myCell, separator)(1)
Next myCell
End Sub
以下是步骤:
答案 1 :(得分:0)