Type mismatch on: <name>

The following conditions could have caused this error.

  • You tried to pass an argument to a sub or function by reference, but the data types of the argument and the corresponding parameter do not match.

    Pass the argument by value or pass an argument of the correct data type.

  • You tried to pass an array, a list, or an object reference to a function or sub, but the corresponding parameter is not defined as one of these or as a Variant.

    Pass an argument of the correct kind.

  • You tried to pass a scalar value to a function or sub, but the corresponding parameter is defined as an array, a list, or an object reference variable.

    Pass an argument of the correct kind.

  • You tried to assign an instance of a user-defined data type to a Variant. For example:
    Type myType
       A As Integer
    End Type
    Dim typeInst As myType
    Dim varV As Variant
    varV = typeInst		' Illegal

    This is not allowed. Remove the assignment statement.

  • You used a Set statement to try to assign a value other than an object reference to an object reference variable (or a Variant holding an object reference). For example:
    Class MyClass  
       ' ...
    End Class
    Dim X As New MyClass
    Dim N As Integer
    N% = 5
    Set X = N%             ' Illegal

    This is not allowed. Remove the assignment statement.

  • You used a Set statement to try to assign an object reference to something other than an object reference variable or a Variant. For example:
    Class MyClass
       ' ...
    End Class
    Dim X As New MyClass
    Dim N As Integer
    Set N% = X            ' Illegal

    This is not allowed. Remove the assignment statement.

  • You used a Set statement to try to assign an object reference variable of one class to an object reference variable of another class. You can only do this when the variables designate instances of the same class or when the target variable designates a base class and the variable whose value is being assigned designates a derived class from that base. For example:
    Class MyClass
       ' ...
    End Class
    Class BaseClass
       ' ...
    End Class
    Class DerivedClass As BaseClass
       ' ...
    End Class
    Dim A As New MyClass
    Dim B As New BaseClass
    Dim D As New DerivedClass
    Set B = A                ' Illegal
    Set D = B                ' Illegal
    Set B = D               ' Legal

    Remove or revise the assignment.

  • You used a Set or Set...New statement to try to create an object (class instance) and assign a reference to it to a variable that is not an object reference variable or a Variant.
    Class MyClass
       ' ...
    End Class
    Dim X As New MyClass
    Dim N As Integer
    Set N% = New MyClass   ' Illegal

    Remove or revise the assignment.

  • You used a Set or Set...Bind statement in which the target variable is not an object reference variable or a Variant holding an object reference.
  • You used a With statement whose target is not an object reference variable or a Variant containing an object reference. The With statement can only be used to operate on objects.
  • A ReDim statement contains a data type that does not match the data type in the declaration of the array, or the data type in a previous ReDim statement whose target was that array.

    Change the data type in the ReDim statement so that it matches the data type of the declaration or previous ReDim statement whose target was that array, or remove the data type from the ReDim statement--once you specify a data type for a dynamic array, it is not necessary to specify the data type again in subsequent ReDim statements.

  • You used a variable declared as a non-numeric data type as the count variable in a For statement.

    Replace the count variable with a variable of the appropriate numeric type.