The information in this article applies to:
SYMPTOMSIn Microsoft Excel, when you run a Microsoft Visual Basic for Applications procedure that contains a mathematical calculation, you may receive the following error message:
CAUSEThis 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, you receive this error message when you run the following procedure:
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, 65536, is larger than the range for an Integer data type
(which must be between -32768 and 32767).
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. You also receive this error message when you run the following procedure:
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.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspTo avoid this error message when you perform a mathematical calculation in a Visual Basic procedure, you must convert at least one of the operands to a data type with a range that is greater than the resulting value. This forces the calculation to be performed using the largest data type. To do this, you can use either of the following methods: Method 1Use a data type conversion function, such as CLng in the following example:
Method 2Use a type-declaration character as in the following examples:
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. MORE INFORMATIONThe Help topic for this error message indicates that a possible cause for this error message includes the following: For example, the range allowed for a variable of data type Double is - 1.79769313486232E308 to -4.94065645841247E-324 (for negative values) and 4.94065645841247E-324 to 1.79769313486232E308 (for positive values). The range allowed for a variable for data type Long is -2,147,483,648 to 2,147,483,647. REFERENCESFor a Data Type Summary, choose the Search button in the Visual Basic Reference and type: data types Additional query words: 5.00a 5.00c 7.00a XL98 XL97 XL7 XL5
Keywords : kbprg kbdta kbdtacode PgmDecl PgmHowto PgmVbl KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |