'object required' in vba function for exce

2019-09-06 15:52发布

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

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

Compile error:

object required

And the debug point is on the function header

标签: excel vba
1条回答
神经病院院长
2楼-- · 2019-09-06 16:30

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
查看更多
登录 后发表回答