title: VBA UDF evaluates after every change
body: <p>I have an issue, I thought would be a pretty simple one, but now can't handle it so I guess was wrong.
  I have a UDF that calculates the average of exchange rates between 2 dates</p>
  <pre><code>Option Explicit
  Public Function averageFromRange() As Double
  
  Dim sh As Worksheet
  Set sh = ThisWorkbook.Worksheets(&quot;Exchange Rates&quot;)
  
  Dim dateStart As Date: dateStart = sh.range(&quot;G1&quot;).Value
  Dim dateEnd As Date: dateEnd = sh.range(&quot;G2&quot;).Value
  
  Dim myRange As String
  Dim rangeStart As range
  Dim rangeEnd As range
  
  Set rangeStart = sh.range(&quot;A:A&quot;).Find(What:=CStr(dateStart), LookAt:=xlWhole, LookIn:=xlValues).Offset(0, 1)
  Set rangeEnd = sh.range(&quot;A:A&quot;).Find(What:=CStr(dateEnd), LookAt:=xlWhole, LookIn:=xlValues).Offset(0, 1)
  
  If rangeStart Is Nothing Then
      MsgBox (&quot;Date &quot; &amp; dateStart &amp; &quot; out of range&quot;)
  End If
  
  If rangeEnd Is Nothing Then
      MsgBox (&quot;Date &quot; &amp; dateEnd &amp; &quot; out of range&quot;)
  End If
  
  If Not (rangeStart Is Nothing Or rangeEnd Is Nothing) Then
      myRange = rangeStart.Address &amp; &quot;:&quot; &amp; rangeEnd.Address
      averageFromRange = Application.WorksheetFunction.Average(range(myRange))
  End If
  End Function
  </code></pre>
  <p>Any change in the entire workbook (apart from the sheet in which the function is called) re-evaluates the function to #VALUE!. I tried both parametrizing the UDF to have these dates as input params, and activating the sheet. I have no other ideas how to handle this issue. Could you help me out?</p>