check if string contains aaa

  • Hello,


    I am looking for a VBA-way to check whether a certain string contains the other string.


    Eg:
    string1 = "Hello World"
    string2 = "Hello everybody"


    teststring = "orld"


    String1 contains the teststring, string2 does not.


    Is there an easy way?


    I was playing around with the worksheetfunction find but this gives an error if the teststring is not found


    Kind regards


    Peter

  • Re: check if string contains aaa


    In VBA you coud use Instr



    As for worksheet functions, how about FIND or SEARCH ?

  • Re: check if string contains aaa


    Try this:



    Hope this helps


    Alastair

    Einstein:
    Things should be made as simple as possible, but not any simpler


    Be sure to check out TemplateZone for all your Microsoft Office Needs.
    Get OfficeReady Professional 3.0 here!

  • Re: check if string contains aaa


    if you like the find functions output (except for the error when teststring is missing) you may want to try something like this:
    =if(iserror(find. . . . . .);"not found";find(..........))

    In formulae, depending on your locale, you might have to replace ; with , or vice versa.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!