vba “无法获取 WorksheetFunction 类的 find 属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16276051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:52:36  来源:igfitidea点击:

“Unable to get find property of WorksheetFunction class

vbaexcel-vbaexcel

提问by Afnan

I am new to vba Below the code is to find the match between two ID in excel if it match then put the new value in the new cell. The problem is when debug appear “Unable to get find property of WorksheetFunction class".

我是vba的新手下面的代码是在excel中找到两个ID之间的匹配,如果匹配,然后将新值放入新单元格中。问题是当调试出现“无法获取 WorksheetFunction 类的 find 属性”时。

Dim lMatch As Long
For i = 0 To 112
    For j = 0 To 540
    lMatch = Application.WorksheetFunction.Find(Cells(2 + i, "A").Value, Cells(2 + j, "H").Value)
        If lMatch > 0 Then
            ActiveSheet.Cells(2 + i, "B").Value = ActiveSheet.Cells(2 + j, "I").Value
        End If
    Next j
Next i

回答by Widor

I believe WorksheetFunction.Find()will throw an error if what you're trying to find doesn't exist.

WorksheetFunction.Find()如果您要查找的内容不存在,我相信会抛出错误。

I suggest using a different function such as InStr()to achieve what you seem to be attempting.

我建议使用不同的功能InStr()来实现您似乎正在尝试的功能。

Or, if you must, use On Errorto redirect program flow when it can't find the value.

或者,如果必须,使用On Error它在找不到值时重定向程序流。

回答by mattboy

I don't think WorksheetFunction.Find() is what you need, it's the other Find method that's applied to ranges. How about this?

我不认为 WorksheetFunction.Find() 是你需要的,它是应用于范围的另一个 Find 方法。这个怎么样?

Dim lMatch As Range
For i = 0 To 112
    For j = 0 To 540
    Set lMatch = Cells(2 + i, "H").Find(Cells(2 + i, "A").Value)
        If Not lMatch Is Nothing Then
            ActiveSheet.Cells(2 + i, "B").Value = ActiveSheet.Cells(2 + j, "I").Value
        End If
    Next j
Next i

回答by sanjiv

Kindly check Find function correctly below is the correct format of find function Find("A",cells(2+i))

请正确检查下面的查找函数是查找函数 Find("A",cells(2+i)) 的正确格式