title: UDF value error for complex itterative function
body: <p>I want to create an UDF for my excel worksheet. However when I select my input for my UDF I get a value error. Can someone help me?</p>
  <p>Code and images below:</p>
  <p>code:</p>
  <pre><code>Public Function pipediameter(Pth As Double) As Double
  
  
  Dim D As Double
  
  
  p = 150
  Tv = 30
  T = 55
  k = 0.000045
  vi = 4
  a = (1.729 * (10 ^ (-6))) / ((1 + (T / 25)) ^ 1.165)
  rho = 988
  Cp = 4180
  
  di = 1
  i = 1
  
      While i &lt;= 10
      v = 4 * Pth / (3.14 * di ^ 2 * Cp * rho * Tv)
      Re = v * di / vi
      B1 = (0.774 * Log(Re) - 1.41) / (1 + 1.32 * Sqr(k / di))
      B2 = ((k * Re) / (3.7 * di)) + (2.51 * B1)
      Y = (B1 - ((B1 + (2 * (Log(B2 / Re) / Log(10)))) / (1 + (2.18 / B2)))) ^ (-2)
      
      D = (((8 * Y) / (p * rho)) * ((Pth) / (3.14 * Cp * Tv)) ^ 2) ^ 0.2
      
      
      di = D
      i = i + 1
      Wend
  
  
  pipediameter = D
  End Function
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Aglsw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Aglsw.png" alt="1" /></a></p>