The following examples are provided from the VBA overflow error help:
Dim x As Long
x = 2000 * 365 ' gives an error
Dim x As Long
x = CLng(2000) * 365 ' fine
I would think that since it is assumed that the Long data type can contain 32-bit numbers, the first example will work fine.
I ask about this because I have code like this:
Dim Price as Long
Price = CLng(AnnualCost * Months / 12)
and this causes an overflow error when the AnnualCost is 5000 and the month is 12.
What am I missing?
source
share