简体   繁体   English

使用功能时出现VBA #VALUE!”错误

[英]VBA #VALUE!" error while using a Function

Still one hair remaining... not for long 还剩下一根头发...时间不长

This : 这个 :

Function Around(Compare As String)

Around = (Range(Compare).Value = Range(Compare).Offset(-1, 0).Value) Or (Range(Compare).Value = Range(Compare).Offset(1, 0).Value)

End Function

generates a #VALUE! 产生#VALUE! in the cell that calls it 在调用它的单元格中

I cannot figure out why 我不知道为什么

Any clues ? 有什么线索吗?

I think #Value error while accessing user defined function in VBA does not apply here. 我认为在VBA访问用户定义的函数时出现#Value错误在这里不适用。

I'm guessing you're typing the formula in like =Around(E8) , when you need to type it in as =Around("E8") since Compare is a String : 我猜您在以=Around(E8)输入公式时,由于Compare是一个String因此需要以=Around("E8")输入公式:

IMG1

If you want to type it without quotation marks, then you need to declare Compare as a Range and change some syntax: 如果要键入不带引号的字符,则需要将Compare声明为Range并更改一些语法:

Function Around(Compare As Range)

    Around = (Compare.Value = Compare.Offset(-1, 0).Value) Or (Compare.Value = Compare.Offset(1, 0).Value)

End Function

IMG2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM