title: Excel VBA #Value! Error
body: <p>I have the following function that when I run it says #value! error.</p>
  
  <p>I would appreciate any help.</p>
  
  <pre><code>Function Bootstrap(S As Object, Z As Object, L As Double)
  
      Dim j As Integer
      Dim a() As Double
      Dim b() As Double
      Dim n As Integer
      Dim Q() As Double
      Dim sum As Double
      Dim P As Double
  
      ReDim a(1 To n)
      ReDim b(1 To n)
      ReDim Q(1 To n)
  
      dt = 1
      sum = 0
      Q(0) = 0
  
      For j = 1 To n - 1
          S.Cells(j, 1).Value = a(j)
          Z.Cells(j, 2).Value = b(j)
          P = Z(j) * (L * Q(j-1) - (L + dt * a(n) * Q(j))
          sum = sum + P
      Next j
  
      Bootstrap = sum
  
  End Function
  </code></pre>
  
  <p>Bootstrapping function calculates the following value
  In fact I am trying to calculate this  formula 
  Q(t,Tn)=(∑(j=1)to(n-1) Z(t,Tj)<em>[LQ(t,Tj-1)-(L+dt</em>Sn)<em>Q(t,Tj)]/[Z(t,Tn)</em>(L+dt*Sn)]  +(Q(t,Tn-1)<em>L)/(L+dt</em>Sn)</p>
  
  <p>Inputs given are[S1 ,S2,….Sn ],[Z(t,T1),Z(t,T2)…..Z(t,Tn)]and and L=0.4</p>