Looking for VBA using FIND on a list of words, not just one word

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

I have some VBA 2003 that searches for text within a range which works great. It searches for the word TRACK in rows 1 and 2.

Set aRange = Range("a1:iv2").Find(What:="TRACK", LookAt:=xlWhole, MatchCase:=False)

I need to test for a list of words (TRACK, PO NUMBER, INVOICE, SUPPLIER). I don't want to repeat the code several times, once for each word to be tested. How can I place this logic inside a loop and have it test each word in a list? The list of words will be in the code and not come from the user.

Thanks,

GL
 
Like this?

Code:
Sub Test()
    Dim Word As Variant
    Dim aRange As Range
    For Each Word In Array("TRACK", "PO NUMBER", "INVOICE", "SUPPLIER")
        Set aRange = Range("a1:iv2").Find(What:=Word, LookAt:=xlWhole, MatchCase:=False)
        If Not aRange Is Nothing Then Exit For
    Next Word
    MsgBox aRange.Address
End Sub
 
Upvote 0
Andrew,

EXCELLENT!! You provided exactly what I needed and in extremely short order.

Happy Holidays to you and your family,

GL
:biggrin:
 
Upvote 0

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