title: VBA Variant Overflow
body: <p>I'm running the below function that I found online</p>
  <pre><code>Function ConvertStringToNumber(str As Variant) As Long
  
      Dim retval As Variant
      Dim i As Integer
  
      retval = &quot;&quot;
  
      For i = 1 To Len(str)
          If Mid(str, i, 1) &gt;= &quot;0&quot; And Mid(str, i, 1) &lt;= &quot;9&quot; Then
              retval = retval + Mid(str, i, 1)
          End If
      Next
  
      ConvertStringToNumber = retval '''''''''ERROR HERE
  
  End Function
  </code></pre>
  <p>I'm receiving the error <code>Run-time error '6': Over Flow</code>, from what I've found online it has to do with my system resources</p>
  <p>These are the inputs I've attempted:</p>
  <blockquote>
  <p>&quot;3aaab   23as454s24h23423ad&quot;</p>
  <p><strong>Result: Overflow</strong></p>
  <p>&quot;3aaab   23as454s24hhhhhhhhhhhhhhhhhhhhhhad&quot;</p>
  <p><strong>Result: 32345424</strong></p>
  <p>&quot;^<em>&amp;asdasd^&amp;sdasd</em>^&amp;^6776**^*&amp;^asdasd&quot;</p>
  <p><strong>Result: 6776</strong></p>
  <p>&quot;5asdasd 7 h4gregw56u 5 45j2dfg  dfgdj46   n5k42n2&quot;</p>
  <p><strong>Result: Overflow</strong></p>
  </blockquote>
  <p>Any idea why some of these are working fine? And some are not?</p>