检查输入框中的某些字符串

时间:2013-12-02 02:00:26

标签: excel vba search excel-2010

我正在尝试在我的宏中实现包含ANDOR函数的搜索函数,在这种情况下使用的正确语句是什么?

如何检测vba中的某些单词?

if input string contains "AND" 
{ 
search for both strings
}

else if input string contains "OR"
{
search for either one 
}

else
{
do regular search
}

1 个答案:

答案 0 :(得分:0)

这是你在找什么?

Function searchCriteria() As String

    Dim str_input As String
    str_input = InputBox("Please enter the string")

    If str_input <> "" Then

        If InStr(1, str_input, "AND", vbTextCompare) Then
            searchCriteria = "search for both strings"
        ElseIf InStr(1, str_input, "OR", vbTextCompare) Then
            searchCriteria = "search for either one"
        Else
            searchCriteria = "do regular search"
        End If

    End If

End Function