Excel:可以通过这种方式进行部分排序吗? [关闭]

问题描述 投票:0回答:2

假设在表格的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行....

这该怎么做。有什么办法/配方吗?

excel excel-formula excel-2007
2个回答
0
投票

如果您的数据在A列上,则将其粘贴在B列上:= ABS(VALUE(MID(A1; SEARCH(“zip - ”; A1; 1)+3; 7)))此提取只是邮政编码。

按照以下5个步骤:

01

02

03

04

05


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. 输入:

enter image description here

  1. 将分隔符放入字符串并对其进行排序后:

enter image description here

  1. 排序后删除第一部分:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.