This error message appears when the mathematical calculation involves
numbers or variables of one data type, such as
Integer, and you assign the result of the calculation to a variable of a different data type, such as
Double or
Long, even if the result of the calculation is within the range of the data type for the resulting variable. For example, the error message appears when you run the following procedure:
Sub Test()
Dim MyVarInteger As Integer
Dim MyVarDouble As Double
MyVarInteger = 256
MyVarDouble = 256 * MyVarInteger
End Sub
The error message occurs in this case because the number 256 is a constant
of
Integer data type. Because the variable MyVarInteger is also a value of
Integer data type, the multiplication calculation is performed as an
Integer calculation. The error message occurs because the result of the calculation, 65,536, is larger than the range for an
Integer data type (which must be between -32,768 and 32,767).
By declaring the result, MyVarDouble, as
Double data type, the calculation multiplies the two
Integer data types and then attempts to convert the result to a
Double data type. Because the result is not within the range for an
Integer data type, the error occurs before the result is converted to the
Double data type.
The error message also appears when you run the following procedure:
Sub Test2()
x = (3832908 * 1000) / (2 * 218706)
MsgBox x
End Sub
In this example, because the values in the calculation are constants, you
cannot dimension the resulting variable, x, as
Double, because you cannot convert an
Integer to a
Double data type
internally by assigning the result of a calculation that contains an
Integer to a
Double data type.