1

Hope somebody can help me.

I wrote the following function which doesn't allow me to search text within text and return a result:

Function ErrorLabel (ErrorMessage as string) as string
    If ErrorMessage = "modified" Or "weight" then
        ErrorLabel = "Valid error"
    End If
End Function

Can somebody please explain how I can introduce another function find or search that allows me to search within a text?

2
  • Sorry I’m just starting to learn programming in VBA. Reading the suggested post didn’t answer my question for me. I just want to search within a cell and see whether the word exist in the cell and return a result. My question is how can I add the find function within a IF function. Commented Jul 13, 2018 at 11:38
  • ErrorMessage = "modified" Or "weight" doesn't mean what you seem to think it means. You would need ErrorMessage = "modified" Or ErrorMessage = "weight" Commented Jul 13, 2018 at 18:26

1 Answer 1

1

It looks like you want to see if either keyword is within the string you are passing in.

Function ErrorLabel (ErrorMessage as string) as string
    If cbool(instr(1, ErrorMessage, "modified", vbtextcompare)) Or _
       cbool(instr(1, ErrorMessage, "weight", vbtextcompare)) then
        ErrorLabel = "Valid error"
    else
        ErrorLabel = "Invalid error"
    End If
End Function
Sign up to request clarification or add additional context in comments.

Comments

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.