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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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