Forum Discussion
temporalnaut
Oct 06, 2020Copper Contributor
Find a list of words in multiple columns
Hi, please, I use this formula in Excel to find out which cells contain certain text: =IF(COUNT(SEARCH({"white","blue","red","black"},B1)),"Yes","") As you can see, the formula looks for text in ce...
- Oct 06, 2020
Try this formula:
=IF(SUM(COUNTIF(A1:Q1,{"*white*","*blue*","*red*","*black*"})),"Yes","")
HansVogelaar
Oct 06, 2020MVP
That is much more complicated. The only way I can think of is to store the list of colors in a range, and to use a custom VBA function:
Function FindText(rng As Range, ParamArray args()) As String
Dim c As Variant
Dim c1 As Range
Dim w As Variant
Dim s As String
Dim v As String
For Each c In args
If TypeName(c) = "Range" Then
For Each c1 In c
v = " " & c1.Value & " "
For Each w In rng
If InStr(1, v, " " & w.Value & " ", vbTextCompare) Then
s = s & vbLf & Trim(v)
Exit For
End If
Next w
Next c1
Else
v = " " & c & " "
For Each w In rng
If InStr(1, v, " " & w.Value & " ", vbTextCompare) Then
s = s & vbLf & Trim(v)
Exit For
End If
Next w
End If
Next c
If s <> "" Then
FindText = Mid(s, 2)
End If
End Function
Let's say that you entered the words white, blue, red and black in A3:A6, and that you want to return the values of the cell(s) in A1, C1, F1, H1:K2, D2 and L1:P1 that contain at least one of those words (matching whole words only).
The formula would be
=FindText(A3:A6,A1,C1,F1,H1:K2,D2,L1:P1)
Turn on Wrap Text for the cell with the formula.
Make sure that you save the workbook as a macro-enabled workbook (.xlsm) and that you allow macros when you open the workbook.
temporalnaut
Oct 07, 2020Copper Contributor
thank you all for help