"Run-time error '424': Object Required"
"Run-time error '424': Object Required"
我想要一个带有两个参数的函数,一个搜索单元格和一个要在其中搜索的单元格,其中搜索单元格包含一个逗号分隔的列表。我想要测试每个元素以查看它是否在 'search in' 单元格中。例如:
List_of_String: word1, word2, word3
Where_to_Search: bbbbbword1 'Return TRUE'
Where_to_Search: bbbbhhhhhmmmmm 'Return FALSE
我写了:
Function Search_in_String(List_of_Strings_to_Search As String, Where_to_Search As String)
String_array = Split(List_of_Strings_to_Search, ",")
Dim is_in_num As Integer
Dim is_in As Boolean
is_in = False
For i = 0 To (UBound(String_array) - 1)
is_in_num = InStr(Where_to_Search, Trim(String_array(i)))
If is_in_num > 0 Then is_in = True
If is_in Then Exit For
Next i
Search_in_String = is_in
End Function
Sub test()
MsgBox Search_in_String(BJ7.Value, Bk7.Value)
End Sub
我用来测试 Search_in_String 函数的 test() 函数(我认为它也不起作用)。当我进入 (F8) 时出现错误:
Run-Time error '424':
Object required
为此更改子测试():
Sub test()
MsgBox Search_in_String(Range("BJ7").Value, Range("BJ7").Value)
End Sub
我想要一个带有两个参数的函数,一个搜索单元格和一个要在其中搜索的单元格,其中搜索单元格包含一个逗号分隔的列表。我想要测试每个元素以查看它是否在 'search in' 单元格中。例如:
List_of_String: word1, word2, word3
Where_to_Search: bbbbbword1 'Return TRUE'
Where_to_Search: bbbbhhhhhmmmmm 'Return FALSE
我写了:
Function Search_in_String(List_of_Strings_to_Search As String, Where_to_Search As String)
String_array = Split(List_of_Strings_to_Search, ",")
Dim is_in_num As Integer
Dim is_in As Boolean
is_in = False
For i = 0 To (UBound(String_array) - 1)
is_in_num = InStr(Where_to_Search, Trim(String_array(i)))
If is_in_num > 0 Then is_in = True
If is_in Then Exit For
Next i
Search_in_String = is_in
End Function
Sub test()
MsgBox Search_in_String(BJ7.Value, Bk7.Value)
End Sub
我用来测试 Search_in_String 函数的 test() 函数(我认为它也不起作用)。当我进入 (F8) 时出现错误:
Run-Time error '424': Object required
为此更改子测试():
Sub test()
MsgBox Search_in_String(Range("BJ7").Value, Range("BJ7").Value)
End Sub