vba函数中的“对象需要”为excel? [英] 'object required' in vba function for excel?

查看:149
本文介绍了vba函数中的“对象需要”为excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Function RRel(colmn, Optional offst, Optional rng)
    If offst Is Nothing Then Set offst = -1
    If rng Is Nothing Then Set rng = Application.Caller
    RRel = Intersect(colmn, rng.offset(offst, 0).EntireRow)
End Function

当我尝试使用这个excel公式,例如 = RRel(P:P)我得到一个错误:

When I try to use this as an excel formula, e.g., =RRel(P:P) I get an error:

Compile error:

object required

调试点在函数头上

推荐答案

我不了解为什么你需要一个UDF来做到这一点:为什么不用Excel公式来做?
无论如何,如果你坚持你可以尝试这个:

I don't understand why you need a UDF to do this: why not just do it with Excel formulas? Anyway if you insist you can try this:

Function RRel(colmn As Range, Optional offst As Variant, Optional rng As Variant) As Variant
    If IsMissing(offst) Then offst = -1
    If IsMissing(rng) Then Set rng = Application.Caller.Offset(offst, 0)
    RRel = Intersect(colmn.EntireColumn, rng.EntireRow).Value
End Function

这篇关于vba函数中的“对象需要”为excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆