简体   繁体   中英

How to search for multiple strings using .find

Column A has values in the below rows 
A1="This is a test string"
A2="Hello how are you"
A3="Today is a good day"
A4="This is a test match"
A5="What is the time now"
A6="Test cell"
A7="This is true"

I would like to find rows which have both "This" and "test". So the result should be "This is a test string" and "This is a test match" Using excel-vba how can this be done? Do we need to use a nested .find?

Why not use something along the lines of

for i = 1 to 7
    if instr(1, Cells(i, 1), "This", vbtextcompare) > 0 and instr(1, Cells(i, 1), "test", vbtextcompare) Then
        Msgbox Cells(i,1).Value
    end if
next i

You will need to mod this for your specific needs but this will look for both "This" and "test" in a cell and create a message box with the cells contents when found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM