title: #VALUE error with Excel VBA Function
body: <p>In my Excel spreadsheet I have two columns.</p>
  
  <ul>
  <li>A contains strings with the values 'Yes', 'No' or 'Maybe'.</li>
  <li>B contains strings with a year in.</li>
  </ul>
  
  <p>I need a function to determine the number of occurrences of a year in column B, where the equivalent value in column A is 'Yes'.</p>
  
  <p>I currently have the following code:</p>
  
  <pre><code>Function CountIfYearAndValue(Rng As Range, YNM As String, Year As String) As Integer
      Dim count As Integer
      count = 0
  
      For Each c In Rng.Cells
          If (StrComp(Abs(c.Value), Year, vbTextCompare) = 0) And (StrComp(Cells(c.Row, A), YMN, vbTextCompare) = 0) Then count = count + 1
      Next
  
      CountIfYearAndValue = count
  End Function
  </code></pre>
  
  <p>The idea of this code is that we iterate through every cell in the range given (a range on column B) and check if the year is equal to the <code>Year</code> parameter. And if the equivalent cell on column A is equal to the <code>YNM</code> parameter we increment the <code>count</code> variable.</p>
  
  <p>For some reason this code does not work when I use the following parameter:</p>
  
  <pre><code>=CountIfYearAndValue('Years'!B1:B7,"Yes","Year 7")
  </code></pre>
  
  <p>It just does the <code>#VALUE</code> error and refuses to display any outcome.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p><strong>Edit:</strong> All of the values in both cells are on of an unformatted datatype ('General') and no cells are blank.</p>