VBA Function not returning a value

Viewed 1636

I have an excel VBA Function that needs to count the cells that are coloured, match a specific string and have another cell blank.

I created it in a test workbook using only a small sample of the data where it worked, but now, when I implement in the main workbook, it returns #Value! I suspect there could be an issue with the string being used, but putting a watch on all my variables shows the function is working as expected but it doesn't actually provide the return value.

Here is the code. Any input will be very much appreciated

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 Answers
Related