Article ID: 213564 - Last Review: October 10, 2006 - Revision: 3.2 XL2000: ParamArray Must Be Declared as an Array of VariantThis article was previously published under Q213564 SYMPTOMS
When you attempt to run a Visual Basic for Applications macro in Microsoft
Excel, or while you are editing code in a Visual Basic module, you may
receive the following error message:
Compile error: ParamArray must be declared as an array of Variant CAUSE
This error will occur if you have declared a variable as a ParamArray and either of the following conditions are true:
RESOLUTION
Variables declared as ParamArrays must be immediately followed by an open and a close parenthesis, and must be declared either as type Variant or as no type at all. Note that if a data
type is not specified, the variable will default to the Variant data type.
Making this change will allow your macros to work in all versions of Microsoft Excel that support the Visual Basic for Applications macro language. MORE INFORMATION
When you write a custom Visual Basic subroutine function in Microsoft
Excel, the last argument accepted by the function can be declared as a
ParamArray. When you do this, the function will accept one or more values and place them in the specified variable as an array, so that they can then be used within the function. For example, if you have the following function:
When you declare a variable as a ParamArray in versions of Microsoft Excel earlier than Excel 97, you can sometimes omit the open and close parentheses immediately following the variable. Specifically, if the variable is declared within a Declare statement, the parentheses may be omitted. For example: In order for the statement to work, you must add open and close parentheses immediately after the variable name, as follows:
Valid ParamArrays Invalid ParamArrays
-----------------------------------------------------
ParamArray A() ParamArray C() As Integer
ParamArray B() As Variant ParamArray D() As Double
ParamArray E() As String
ParamArray F() As Boolean
ParamArray G() As Long
213277
(http://support.microsoft.com/kb/213277/EN-US/
)
XL2000: Methods to Use Custom Functions with Varying Arguments
| Article Translations
|
Back to the top
