如果我有一系列值,如何提取包含特定单词的所有值?
例如:
那有什么更好的吗
=IFERROR(INDEX(INDIRECT("A"&MATCH(D2,$A$2:$A$21,0)+2&":A21"),
MATCH("*"&$C$1&"*",INDIRECT("A"&MATCH(D2,$A$2:$A$21,0)+2&":A21"),0)),"")
我更喜欢公式而不是 VBA,但也可以随意发布 VBA 解决方案。
如果我有一系列值,如何提取包含特定单词的所有值?
例如:
那有什么更好的吗
=IFERROR(INDEX(INDIRECT("A"&MATCH(D2,$A$2:$A$21,0)+2&":A21"),
MATCH("*"&$C$1&"*",INDIRECT("A"&MATCH(D2,$A$2:$A$21,0)+2&":A21"),0)),"")
我更喜欢公式而不是 VBA,但也可以随意发布 VBA 解决方案。
I trick I've learnt will help here and no VBA is required. Put this in D2 and drag down:
{=INDEX(A:A,
SMALL(IF(ISNUMBER(SEARCH("*"&$C$1&"*",$A$2:$A$11)),
ROW($A$2:$A$11),
MAX(ROW($A$2:$A$11))+1)
,ROW()-1))}
Note: This is an array formula and needs to be entered with Control + Shift + Enter.
Explanation:
index(<arr>, <nbr>)
will get the value of the row we find;search(<string>, <arr>)
will find all values in the array that match and is the reason for the array formula;if
function will return the row number if a match exists and if not set a default row number, in this case the last one + 1; andsmall(<arr>, <n-th>)
function will now return the nth smallest row number starting, in this case the cell has to be in row 2 otherwise the -1
needs to be altered.Non-VBA Pivots initiated by VBA:
I've found the pivot tables bring a large improvement in performance:
You can use the in-built contains or search ability
Or use VBA on the Worksheet
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" Then
With Me.PivotTables("PivotTable2").PivotFields("name")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionContains, Value1:=Target
End With
End If
End Sub