VBA函数未返回值

时间:2017-09-13 08:32:26

标签: excel vba

我有一个excel VBA函数,需要计算着色的单元格,匹配特定字符串并将另一个单元格留空。

我在测试工作簿中创建了它,只使用了一小部分数据样本,但现在,当我在主工作簿中实现时,它返回#Value!我怀疑使用的字符串可能存在问题,但是对我的所有变量进行监视会显示该函数正在按预期工作,但它实际上并不提供返回值。

这是代码。任何输入都将非常感激

Function FundInStarted(rSample As Range, rKRM As Range, rColNum As Range, rArea As Range) As Long

    Dim rAreaCell As Range
    Dim lMatchColor As Long
    Dim lCounter As Long
    Dim sKRMMatch As String
    Dim lColNumOff As Long

    lMatchColor = rSample.Interior.Color
    sKRMMatch = rKRM.Value2
    lColNumOff = rColNum

    For Each rAreaCell In rArea
        If rAreaCell.Interior.Color = lMatchColor And rAreaCell.Offset(0, -lColNumOff) = sKRMMatch And rAreaCell.Value = "" Then
            lCounter = lCounter + 1
        End If
    Next
    FundInStarted = lCounter
End Function

0 个答案:

没有答案