Share via


Visual Basic for Applications Reference

Type mismatch (Error 13)

See Also    Specifics

Visual Basic is able to convert and coerce many values to accomplish data type assignments that weren't possible in earlier versions. However, this error can still occur and has the following causes and solutions:

  • The variable or property isn't of the correct type. For example, a variable that requires an integer value can't accept a string value unless the whole string can be recognized as an integer.

    Try to make assignments only between compatible data types. For example, an Integer can always be assigned to a Long, a Single can always be assigned to a Double, and any type (except a user-defined type) can be assigned to a Variant.

  • An object was passed to a procedure that is expecting a single property or value.

    Pass the appropriate single property or call a method appropriate to the object.

  • A module or project name was used where an expression was expected, for example:

    Debug.Print MyModule
    

    Specify an expression that can be displayed.

  • You attempted to mix traditional Basic error handling with Variant values having the Error subtype (10, vbError), for example:

    Error CVErr(n)
    

    To regenerate an error, you must map it to an intrinsic Visual Basic or a user-defined error, and then generate that error.

  • A CVErr value can't be converted to Date. For example:

    MyVar = CDate(CVErr(9))
    

    Use a Select Case statement or some similar construct to map the return of CVErr to such a value.

  • At run time, this error typically indicates that a Variant used in an expression has an incorrect subtype, or a Variant containing an array appears in a Print # statement.

    To print arrays, create a loop that displays each element individually.

For additional information, select the item in question and press F1.