Checkword macro multiple results

MichaelGood

New Member
Joined
Jun 27, 2019
Messages
1
Hi there,
I am trying to set up a search function for a list of approved chemicals based on a partial search criteria using Checkword macro which seems to work quite well in providingmultiple results.

However, when there is no search criteria (empty box) itreturns every result rather than no result.
Any ideas on how to tweak this would be appreciated.

Macro:
Function CheckWords(rng As Range,lookupwords As String, Optional num As Long = 1) As String

Dimlookup() As String
Dimi As Long, Ctr As Long

Dimc As Range

DimbPassed As Boolean



lookup = Split(lookupwords)

ForEach c In rng

bPassed = True
For i = 0 To UBound(lookup)

If InStr(1, " " & c.Value, " " & lookup(i),vbTextCompare) = 0 Then

bPassed = False

Exit For

End If

Next i
IfbPassed Then Ctr = Ctr + 1
IfCtr = num Then
CheckWords = c.Value
Exit For
End If
Nextc
End Function

Cell D2 =CheckWords(A$2:A$71,D$1,ROWS(D$2:D2))
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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