0

How can I check if a cell contains two separate strings in a cell? I tried:

ElseIf InStr(1, UCase(testVal), UCase("goku"), 1) And InStr(1, UCase(testVal), UCase("vegeta"), 1) Then
            Worksheets("Export Worksheet").Cells(i, 18).EntireRow.Interior.ColorIndex = "4"

However, this does not work...

If I use

ElseIf InStr(1, UCase(testVal), UCase("goku"), 1) & InStr(1, UCase(testVal), UCase("vegeta"), 1) Then
            Worksheets("Export Worksheet").Cells(i, 18).EntireRow.Interior.ColorIndex = "4"

It will highlight the row if "goku" OR "vegeta" are in the cell. However, I need BOTH values to be in the cell.

Please help!

1 Answer 1

2

You want the result of InStr to be great than 0. Also use "And" not "&"

ElseIf InStr(1, UCase(testVal), UCase("goku"), 1) > 0 AND InStr(1,     UCase(testVal), UCase("vegeta"), 1) > 0 Then
        Worksheets("Export Worksheet").Cells(i, 18).EntireRow.Interior.ColorIndex = "4"
Sign up to request clarification or add additional context in comments.

1 Comment

The "&" will concatenate the values returned from InStr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.