高级Excelsorting

我有一个快速的问题。

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

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

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

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

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

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

会给
table得分为1
mirror 100分
sofa的分数是1000

允许简单的数字sorting。

如果一个单元格可能同时包含mirrorsofa那么它将得到101分。在这种情况下,您可以:

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

在这里输入图像描述

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

input

在这里输入图像描述

结果

在这里输入图像描述

 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 

你可以创build一个新的列并使用这个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”是一系列你想要查找的列表。 确保先放更长的条件:即。 “沙发桌”应在“沙发”或“桌子”之前。

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

如果您只想显示列表中的所有“表”,为什么不在search字段中使用自动filter结束types表。 这种方式只会显示string中的“表”字样。 所有其他行将被隐藏。

问候,

罗伯特