XL98: Type Mismatch: Array or User Defined Type Expected

ID: Q192362

The information in this article applies to:

SYMPTOMS

In Microsoft Excel 98 Macintosh Edition, when a Microsoft Visual Basic for Applications procedure passes the value of one array to another array, if the data types of the two arrays are not compatible, you may receive one of the following error messages:

   Type mismatch: Array or User Defined Type Expected.

   -or-

   Compile error:
   Type mismatch: array or user-defined type expected

These error messages are not clear. A more accurate error message is the following:

   Type mismatch: aarrays not of compatible type

RESOLUTION

To make sure that the data types for both arrays are compatible, dimension both arrays with the same data type.

MORE INFORMATION

Steps to Reproduce Behavior

1. In Microsoft Excel, create a new workbook.

2. Start the Visual Basic Editor by pressing OPTION+F11.

3. In the module, type the following procedures:

      Sub First()
         Dim A(1 to 20) As Double
         Second A()
      End Sub

      Sub Second(B() As Single)
      End Sub

4. Click Macro on the Tools menu. Select the macro titled First, and
   click Run.

   In Microsoft Excel 97, click Macros on the Tools menu. Click First, and
   then click Run.

   At this point you should receive one of the error messages shown above.

The correct syntax would be to have the data types of both arrays compatible. For example, type the following procedures on the same module sheet as the preceding example.

    Sub Correct()
       Dim A(1 to 20) As Double
       Example A()
    End Sub

    Sub Example(B() As Double)
    End Sub

NOTE: The data type of both arrays is double.

Additional query words: XL98

Keywords          : kbdta xlvbainfo 
Version           : MACINTOSH:98
Platform          : MACINTOSH
Issue type        : kbprb

Last Reviewed: September 12, 1998