<p>From the help for the Overflow Error in VBA, there's the following examples:</p>

<pre><code>Dim x As Long
x = 2000 * 365 ' gives an error

Dim x As Long
x = CLng(2000) * 365 ' fine
</code></pre>

<p>I would have thought that, since the Long data type is supposed to be able to hold 32-bit numbers, that the first example would work fine.</p>

<p>I ask this because I have some code like this:</p>

<pre><code>Dim Price as Long
Price = CLng(AnnualCost * Months / 12)
</code></pre>

<p>and this throws an Overflow Error when AnnualCost is 5000 and Months is 12.</p>

<p>What am I missing?</p>

2000 and 365 are Integer values.  In VBA, Integers are 16-bit signed types, when you perform arithmetic on 2 integers the arithmetic is carried out in 16-bits.  Since the result of multiplying these two numbers exceeds the value that can be represented with 16 bits you get an exception.  The second example works because the first number is first converted to a 32-bit type and the arithmetic is then carried out using 32-bit numbers.  In your example, the arithmetic is being performed with 16-bit integers and the result is then being converted to long but at that point it is too late, the overflow has already occurred.  The solution is to convert one of the operands in the multiplication to long first:
```
```
Dim Price as Long
Price = CLng(AnnualCost) * Months / 12
```
```