title: #value error in user defined function
body: <p>I wrote a VBA function that checks several things and returns a code
  that triggers conditional formatting. Everything works well except
  that the formula often triggers a <code>#value</code> error. It does this for all
  cells containing the formula (a few thousands). The error appears
  whenever I open another workbook. It sometimes happen when I don't
  open another workbook.</p>
  
  <p>The function is here:</p>
  
  <pre><code>  Function jjcheck(STDTRow As Integer, cuCOL As Integer, cuMax As Integer, trmEnd As Integer, trmEMax As Integer, worksheetSRC As String, lstCTCT As Date) As Variant
     'use in spreadsheet =jjcheck(B2,Variables!$G$4,Variables!$G$2,Variables!$F$2,"SRM",U2)
     '=jjcheck(B2,Variables!$G$4,Variables!$F$4,Variables!$G$2,Variables!$F$2,"SRM",IF(ISBLANK(U2),TODAY(),U2))
     Dim V() As String, dayMax As Integer, lookup As Date, theDiff As Integer, lstContact As String
     V = Split(ActiveWorkbook.ActiveSheet.Cells(1, 2).Value, "-"): dayMax = V(1): theDiff = 256
     lookup = lstCTCT
     theDiff = DateDiff("d", lookup, Date): lstContact = ""
     If theDiff &gt; dayMax Then lstContact = "Alert"
     Dim STDcu As Integer, STtrmEnd As Date, daysTOtrmend As Integer
     STDcu = ActiveWorkbook.Worksheets(worksheetSRC).Cells(STDTRow, cuCOL).Value
     STtrmEnd = ActiveWorkbook.Worksheets(worksheetSRC).Cells(STDTRow, trmEnd).Value
     daysTOtrmend = DateDiff("d", Date, STtrmEnd)
     If STDcu &lt; cuMax And daysTOtrmend &lt; trmEMax Then
         jjcheck = "CHECK" &amp; lstContact
     ElseIf daysTOtrmend &lt; trmEMax / 2 Then
         jjcheck = "ETerm" &amp; lstContact
     Else
         jjcheck = "" &amp; lstContact
     End If
  End Function
  </code></pre>
  
  <p>suspecting that the error might be due to the times cell <code>U2</code> is empty,I
  changed what I put for <code>lstCTCT</code> to <code>IF(ISBLANK(U2),TODAY(),U2)</code>
  That did not seem to help.<a href="http://i.stack.imgur.com/ojz9g.png" rel="nofollow">The image shows what happens in the worksheet</a>
  Thanks for any insight you can give on that.</p>