error using a personal VBA function
<p>I created a sheet containing some values; it is a calendar that displays some informations for each day of the year.
for each day, I have an information given as a letter.
e.g. February, 3rd 2016 --> "M"</p>

<p>I also have a VBA function that computes the sum of the cells of a month equal to - say - "M".</p>

<p>My first try was to modify in VBA the value of the cell receiving the sum, with a VBA function; but my problem is that users could manually edit some cells of the calendar, so I would like to the sum cell to be recomputed, automatically, and now it doesn't.</p>

<p>here is my function, located in a module named "abc":</p>

<pre><code>Function nombreCellulesDansEtat2() As Integer
Application.Volatile
Dim moisSub
Dim équipeSub
Dim étatSub
moisSub = 1
équipeSub = 1
étatSub = "M"

Dim ligneDépart As Integer
ligneDépart = 5 + (moisSub - 1) * 9
Dim ligneEnCours As Integer
ligneEnCours = ligneDépart + équipeSub

Dim cellule
Dim retour As Integer
For Each cellule In sh.Range("B" &amp; ligneEnCours &amp; ":AF" &amp; ligneEnCours)
    retour = retour + IIf(cellule.Value = étatSub, 1, 0)
Next cellule
nombreCellulesDansEtat = retour


End Function
</code></pre>

<p>please don't focus on the team number("équipeSub" in french), it's not linked to the problem.</p>

<p>The cell containing the sum has this formula : </p>

<pre><code>=nombreCellulesDansEtat2()
</code></pre>

<p>and the option of the automatic computing of formulas is enabled(I use excel 365 with windows 10)</p>

<p>the error is that the sum cell contains :</p>

<pre><code>#VALUE!
</code></pre>

<p>and not the required sum.</p>

<p>thank you for having supported my bad english!</p>