Ryan
Ryan

Reputation: 21

How to use 2 functions in VBA

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?

Upvotes: 1

Views: 57

Answers (1)

user4039065
user4039065

Reputation:

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

Upvotes: 1

Related Questions