Type mismatch (Error 13)

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:

  • Cause: 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.

Solution: 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.

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

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

Solution: Specify an expression that can be displayed.

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

      Error CVErr(n) 
    

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

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

      MyVar = CDate(CVErr(9)) 
    

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

  • Cause: 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.

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

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

Note

Interested in developing solutions that extend the Office experience across multiple platforms? Check out the new Office Add-ins model. Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you can build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.