title: VBA if else loop in excel returning #VALUE
body: <p>Hi All in new to using VBA in excel and was trying to create a function that would look at a number and return it as a six digit number. </p>
  
  <p>The function I wrote to try and accomplish this is below but when I use the command =Res(A1) in a cell I just get a #VALUE! as the answer. </p>
  
  <p>The value in cell one at the moment is 30508. </p>
  
  <p>Any help anyone could offer to resolve this would be greatly appreciated. Thanks Guys.</p>
  
  <pre><code>Function Res(myval As Integer) As Integer
  
  Res = 0
  
  If ((myval &gt; 0) And (myval &lt; 10)) Then    
      Res = myval * 100000
  
  ElseIf ((myval &gt; 9) And (myval &lt; 100)) Then
      Res = myval * 10000
  
  ElseIf ((myval &gt; 99) And (myval &lt; 1000)) Then 
      Res = myval * 1000
  
  ElseIf ((myval &gt; 999) And (myval &lt; 10000)) Then  
      Res = myval * 100
  
  ElseIf ((myval &gt; 9999) And (myval &lt; 100000)) Then
      Res = myval * 10
  
  ElseIf ((myval &gt; 999999) And (myval &lt; 10000000)) Then
      Res = myval / 10
  
  Else
      Res = myval
  
  End If
  
  End Function
  </code></pre>