高级Excel排序

时间:2011-10-21 23:05:03

标签: excel excel-formula

我有一个简单的问题。

我有一张Excel工作表..其中包含某些项目的说明:例如:

1) Awesome mirror
2) Another Awesome mirror
3) beautiful table
4) Pretty beautiful lovely sofa
5) one more mirror

and so on...

所以,我想说,我想把所有的镜子放在一起,把所有的桌子放在一起...... 等等...所以基本上可以回复我所有包含“镜子”一词的实例。

关于如何解决这个问题的任何想法?

4 个答案:

答案 0 :(得分:3)

您可以使用如下公式解决方案:

=SUM(COUNTIF(A1,"*"&{"table","mirror","sofa"}&"*")*{1,100,1000})

会给予 table得分为1 mirror得分为100 sofa得分为1000

允许简单的数字排序。

如果某个单元格可能同时包含mirrorsofa,则得分为101.在这种情况下,您可以:

  • 很高兴有一个单独的多场比赛名单
  • 如果您可以提供您希望如何处理多场比赛,我可以进一步调整公式。

enter image description here

答案 1 :(得分:2)

另一种可能性是ADO。当项目出现两次时,这将返回两行。也可以使用ToFind中的另一列允许Not LikeLike '%' & [ToFind] & '%' And Not Like '%' & [NotToFind] & '%'

<强>输入

enter image description here

<强>结果

enter image description here

Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim s As String
Dim i As Integer, j As Integer

''This is not the best way to refer to the workbook
''you want, but it is very convenient for notes
''It is probably best to use the name of the workbook.

strFile = ActiveWorkbook.FullName

''Note that if HDR=No, F1,F2 etc are used for column names,
''if HDR=Yes, the names in the first row of the range
''can be used.
''
''This is the Jet 4 connection string, you can get more
''here : http://www.connectionstrings.com/excel

strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
    & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

''Late binding, so no reference is needed

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open strCon

''[ToFind] is a named range, but it does not have to be.
strSQL = "SELECT DISTINCT [List], [ToFind] " _
       & "FROM [Sheet1$A:A] a, " _
       & "[ToFind] b " _
       & "WHERE List Like '%' & [ToFind] & '%'"

rs.Open strSQL, cn, 3, 3


''Pick a suitable empty worksheet for the results

Worksheets("Sheet2").Cells(2, 1).CopyFromRecordset rs

''Tidy up
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

答案 2 :(得分:0)

您可以创建一个新列并使用此UDF:

Function WhatIsIt(LineItem As Range, AllThings As Range) As String
    Dim rv As String, c As Range
    Dim v As String, thing As String

    v = UCase(LineItem.Cells(1).Value)
    rv = ""

    If Len(v) > 0 Then
        For Each c In AllThings.Cells
            thing = c.Value
            If Len(thing) > 0 And InStr(v, UCase(thing)) > 0 Then
                rv = thing
                Exit For
            End If
        Next c
    End If
    WhatIsIt = rv
End Function

“AllThings”是一个范围,其中列出了您要查找的内容。确保首先使用更长的术语:即。 “沙发桌”应该出现在“沙发”或“桌子”之前。

注意它可以使用一些改进:当一个术语只是项目描述中另一个单词的一部分时,它也会返回匹配。

答案 3 :(得分:0)

如果您只想在列表中显示所有“表格”,为什么不在搜索字段中使用自动过滤器结束类型表。这样,只会出现字符串中带有“Table”字样的项目。所有其他行都将被隐藏。

此致

罗伯特