Excel: 这样可以部分排序吗?
Excel: Is it possible to partially sort this way?
假设在 sheet 的 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 行....
如何做到这一点。有没有way/formula?
如果您可以并且愿意在 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
这些是步骤:
- 输入:
- 将分隔符放入字符串并排序后:
- 删除排序后的第一部分:
如果您的数据位于 A 列,则将其粘贴到 B 列:=ABS(VALUE(MID(A1;SEARCH("zip-";A1;1)+3;7) )) 这只是提取邮政编码。
遵循以下 5 个步骤:
01
02
03
04
05
假设在 sheet 的 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 行....
如何做到这一点。有没有way/formula?
如果您可以并且愿意在 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
这些是步骤:
- 输入:
- 将分隔符放入字符串并排序后:
- 删除排序后的第一部分:
如果您的数据位于 A 列,则将其粘贴到 B 列:=ABS(VALUE(MID(A1;SEARCH("zip-";A1;1)+3;7) )) 这只是提取邮政编码。
遵循以下 5 个步骤: