none
Search for 2 different strings in one line in an input file RRS feed

  • Question

  • I am building an Excel macro which pulls information out of text files if a string is found in that text file. So far the macro is successful in this regard, however I've come upon a scenario where I need to search one line in the text file to see if it contains either of two strings (either one would be contained in the first input line). Here is the line in my macro that I'm using:

    If InStr(InputData, strConfirmationNumber) Or InStr(InputData, strLinkedOrder) <> 0 Then

    'do something

    End if


    strConfirmationNumber and strLinkedOrder change throughout the macro. Unfortunately, if the strLinkedOrder happens to be null and strConfirmationNumber is not found in the input line, the macro still proceeds to continue to 'do something, therefore pulling incorrect data from the file, when reallty I need it to proceed to "End if."

    Can anyone help?

    Monday, February 6, 2017 8:28 PM

All replies

  • Try

    If InStr(InputData, strConfirmationNumber) > 0 And strConfirmationNumber <> "" Or InStr(InputData, strLinkedOrder) > 0 And strLinkedOrder <> "" Then


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, February 7, 2017 12:02 AM