VBA - How to find words from list in a cell?

Fixed

Board Regular
Joined
Apr 28, 2017
Messages
95
Hello!

I have the function:
Code:
IF(SUMPRODUCT(--ISNUMBER(SEARCH(E1:E2,A1)));"yes","no")
that searches the text values from E1:E2 in A1 cell.
How to make the same in VBA?

Thanks in advance!
 
When E1 or E2 is empty, the functions say "yes" instead of "no".
That is what the formula you posted in Message #1 did and you asked us to make VBA do what your formula did.



When E1 or E2 is empty, the functions say "yes" instead of "no".
How to find the non-empty values only?
Try this revised version of the function that I posted earlier...
Code:
[table="width: 500"]
[tr]
	[td]Function FindTxts(SingleCell As Range, RangeOfCells As Range) As Variant
  Dim Cel As Range
  For Each Cel In RangeOfCells
    FindTxts = FindTxts + (Cel.Value <> 0 And InStr(1, SingleCell, Cel.Value, vbTextCompare) > 0)
  Next
  If FindTxts Then FindTxts = "Yes" Else FindTxts = "No"
End Function[/td]
[/tr]
[/table]
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
That is what the formula you posted in Message [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1 [/URL] did and you asked us to make VBA do what your formula did.
I know that your function works as an example from Meassage #1 , but I didn't think about it before, sorry.


Try this revised version of the function that I posted earlier...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Function FindTxts(SingleCell As Range, RangeOfCells As Range) As Variant
   Dim Cel As Range
   For Each Cel In RangeOfCells
     FindTxts = FindTxts + (Cel.Value <> 0 And InStr(1, SingleCell, Cel.Value, vbTextCompare) > 0)
   Next
   If FindTxts Then FindTxts = "Yes" Else FindTxts = "No"
 End Function[/TD]
[/TR]
</tbody>[/TABLE]

The that one works with empty values perfectly, thank you!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top