我使用vba搜索功能时运行时错误1004

问题描述 投票:0回答:1

我正在练习一些功能

当我在下面运行它返回运行时错误1004应用程序定义或对象定义的错误。

Public Sub se()
        a = 2
        While a < 6
            c = WorksheetFunction.IfError(WorksheetFunction.Search("1", "ella"), 100)
            MsgBox c
            a = a + 1
        Wend
End Sub
vba search
1个回答
0
投票

对于您似乎想要实现的目标,我建议使用InStr函数。 InStr将搜索一个字符串并返回它首次出现的位置。如果搜索的字符串未在搜索的字符串中出现,则将返回0

以下是它的使用方法:

InStr( [start], string, substring, [compare] )

一个工作示例c / o Tech on the Net

InStr(1, "Tech on the Net", "the")
'Result: 9'

InStr("Tech on the Net", "the")
'Result: 9'

InStr(10, "Tech on the Net", "t")
'Result: 15'

InStr("Tech on the Net", "z")
'Result: 0'
© www.soinside.com 2019 - 2024. All rights reserved.