Excel 使用FindNext的UDF似乎在没有警告的情况下中止

Excel 使用FindNext的UDF似乎在没有警告的情况下中止,excel,excel-udf,vba,Excel,Excel Udf,Vba,我有以下用户定义的函数,它尝试查找范围内的第n个非空单元格: Option Explicit Function finn_prioritert_oppgave(nummer As Long) As String Dim i As Long, r As Range, c As Range Set r = Range(PDCA.Range("L9"), PDCA.Range("L1048576").End(xlUp)) i = 1 Set c = r.Find(What:="

我有以下用户定义的函数,它尝试查找范围内的第n个非空单元格:

Option Explicit

Function finn_prioritert_oppgave(nummer As Long) As String

  Dim i As Long, r As Range, c As Range

  Set r = Range(PDCA.Range("L9"), PDCA.Range("L1048576").End(xlUp))
  i = 1

  Set c = r.Find(What:="*", LookIn:=xlValues, LookAt:=xlWhole)

  While (Not c Is Nothing) And (Intersect(c, PDCA.Rows(9)) Is Nothing) And (i < nummer)

    Debug.Print c
    Set c = r.FindNext(c)
    Debug.Print c
    Debug.Print CBool(c Is Nothing)
    i = i + 1

  Wend

  If c Is Nothing Then
    finn_prioritert_oppgave = "#N/A"
  Else
    finn_prioritert_oppgave = c.Offset(0, -10).Value
  End If

End Function
选项显式
函数finn_prioritert_oppgive(与字符串一样长)
尺寸i等于长度,r等于范围,c等于范围
设置r=范围(PDCA范围(“L9”)、PDCA范围(“L1048576”)。结束(xlUp))
i=1
设置c=r.Find(What:=“*”,LookIn:=xlValues,LookAt:=xlWhole)
而(不是c是什么)和(相交(c,PDCA.Rows(9))是什么)和(i
以1作为参数运行它效果很好,这可能是因为它不会在-循环时输入
,并点击
FindNext
,但以任何较大的值作为参数运行它会导致调用它的单元格显示
-警报

查看即时窗口中显示的内容也很奇怪,因为执行
FindNext
后的两条
Debug.Print
消息不会打印,尽管我没有收到任何警报

我在immediate窗口中得到的输出,以2作为参数调用的UDF只是一个x:


从中调用函数的区域看起来像(第一行是用1作为参数调用的UDF,第二行是用2作为参数调用的UDF),而包含数据的区域看起来像


所以我想知道的是,为什么
FindNext
无法找到范围内的第二个非空单元格,为什么函数在没有任何警告的情况下中止?

FindNext
在UDF中不起作用。您只需重复原来的
Find
操作。

Darn。有没有什么简单的方法可以查看哪些本机函数可以在UDF中有效使用,还是每次我都要来这里问你一个问题?;)无论如何,谢谢你的帮助!我不知道有一个特定的列表,但我不知道,您不能使用大多数方法(包括
特殊单元格
)和这些属性:
当前数组
当前区域
显示格式