vba 工作表函数内的工作表函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20998305/
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-12 01:16:25  来源:igfitidea点击:

A worksheet function inside a worksheet function

vbaexcel-vbaexcel

提问by lori_m

When working inside worksheets we can nest functions for example: =IFERROR(VLOOKUP(C8, [Table4], 1,0),"")

在工作表中工作时,我们可以嵌套函数,例如: =IFERROR(VLOOKUP(C8, [Table4], 1,0),"")

but when I tried doing this in a macro it produces an error, This line of code is the one I was trying to apply:

但是当我尝试在宏中执行此操作时会产生错误,这行代码是我尝试应用的代码:

  Application.WorksheetFunction.IfError ((Application.WorksheetFunction.VLookup(Range("C8"), [Table4],  1, 0), "")

So, How to nest worksheet functions in VBA?

那么,如何在 VBA 中嵌套工作表函数?

回答by lori_m

You can drop the .Worksheetfunctionmethod and use instead:

您可以删除该.Worksheetfunction方法并使用:

v = Application.IfError(Application.VLookup(Range("C8"), [Table4], 1, 0), "")

or:

或者:

With Application
    v = .IfError(.VLookup(Range("C8"), [Table4], 1, 0), "")
End With

Using Applicationwithout .Worksheetfunctionreturns a variant which will allow for errors or arrays in arguments and return values. So you can also look up a vector of values eg use: Range("C8:C10")in place of Range("C8").

使用Applicationwithout.Worksheetfunction返回一个变体,它允许在参数和返回值中出现错误或数组。因此,您还可以查找值向量,例如 use:Range("C8:C10")代替Range("C8")