Count cells that contain certain letters (Visual Basic)
<p>I'm trying to write a function in VBA that will count the cells that contain certain letters in a specific range. My code so far is</p>

<pre><code>Function letters(list As range) As Double

    Dim limit As Integer
    limit = UBound(list.Value)

    Dim total As Double
    total = 0

    Dim i As Integer

    For i = 1 To limit
        If range(list).Offset(i, 2) = "PD" Then
        total = total + 1
        End If
    Next i

    letters = total

End Function
</code></pre>

<p>So my input is =letters(A1:B6) and lets say B2, B3, and B5 have the text "PD". I expect my answer to be 3 but I get a #value! error. Where am I going wrong?</p>

<p>Thanks in advance.</p>