Mac Excel 2011 VBA UDF无法正常工作 - SET或FIND命令似乎是个问题

1 excel vba excel-vba excel-vba-mac

我正在将电子表格从Excel 2007转换为Mac Excel 2011.我已经尝试了几个小时来解决我的问题,但没有成功,所以任何帮助将不胜感激!

此UDF在范围内查找字符串,然后返回找到的单元格下方一个单元格的值.SET命令在Mac版本中不返回任何内容,但在Excel 2007中有效.

Function FindRng(Fnd As String)
Application.Volatile

Dim Rng As Range
If Fnd = "" Then
    FindRng = 0
    GoTo 109
End If
With Sheets("Matrix").Range("G2:FZ13")
         Set Rng = .Find(What:=Fnd, _
                After:=.Cells(2, 7), _
                LookIn:=xlValues, _
                LookAt:=xlWhole, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, _
                MatchCase:=False)
    If Not Rng Is Nothing Then
        FindRng = Sheets("Matrix").Cells(Rng.Row + 1, Rng.Column).Value
    Else
        FindRng = 0
    End If
End With

109 End Function
Run Code Online (Sandbox Code Playgroud)

Jos*_*ieP 6

Find在2011年从一个单元调用的UDF中不起作用(在Office XP之前的PC版本中存在同样的问题)所以你要么必须循环并测试每个单元格(将数据加载到数组中应该比逐个单元地读取)或使用application.match一次处理一行.