You are currently offline, waiting for your internet to reconnect

Type Mismatch: Array or User Defined Type Expected

This article was previously published under Q121114
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
SUMMARY
In Microsoft Excel, when a Microsoft Visual Basic for Applicationsprocedure passes the value of one array to another array, if the data typesof the two arrays are not compatible, you may receive one of the followingerror 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 thefollowing:
Type mismatch: arrays not of compatible types
RESOLUTION
To make sure that the data types for both arrays are compatible, dimensionboth arrays with the same data type.
MORE INFORMATION

Steps to Reproduce Behavior

  1. In Microsoft Excel, create a new workbook.
  2. From the Insert menu, choose Macro, and then choose Module.

    In Microsoft Excel 97, press ALT+F11 to activate the Visual Basic Editor. Then, click Module on the Insert menu.
  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. From the Tools menu, choose Macro. Select the macro titled First, and choose 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 arrayscompatible. For example, type the following procedures on the same modulesheet 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..
5.00a 5.00c 97 XL97 XL
Properties

Article ID: 121114 - Last Review: 10/11/2006 02:26:16 - Revision: 1.5

  • Microsoft Excel 97 Standard Edition
  • Microsoft Excel 95 Standard Edition
  • Microsoft Excel 5.0 Standard Edition
  • kbdtacode kbinfo kbprogramming KB121114
Feedback