Sửa lỗi run time error 13 type mismatch vba năm 2024

Type Mismatch (Error 13) occurs when you try to specify a value to a variable that doesn’t match with its data type. In VBA, when you declare a variable you need to define its data type, and when you specify a value that is different from that data type you get the type mismatch error 13.

Sửa lỗi run time error 13 type mismatch vba năm 2024

In this tutorial, we will see what the possible situations are where runtime error 13 can occurs while executing a code.

Type Mismatch Error with Date

In VBA, there is a specific data type to deal with dates and sometimes it happens when you using a variable to store a date and somehow the value you specify is different.

In the following code, I have declared a variable as the date and then I have specified the value from cell A1 where I am supposed to have a date only. But as you can see the date that I have in cell one is not in the correct format VBA is not able to identify it as a date.

Sửa lỗi run time error 13 type mismatch vba năm 2024
Sub myMacro()
Dim iVal As Date
iVal = Range("A1").Value
End Sub

Type Mismatch Error with Number

You’re gonna have you can have the same error while dealing with numbers where you get a different value when you trying to specify a number to a variable.

In the following example, you have an error in cell A1 which is supposed to be a numeric value. So when you run the code, VBA shows you the runtime 13 error because it cannot identify the value as a number.

Sửa lỗi run time error 13 type mismatch vba năm 2024
Sub myMacro()
Dim iNum As Long
iNum = Range("A6").Value
End Sub

Runtime Error 6 Overflow

In VBA, there are multiple data types to deal with numbers and each of these data types has a range of numbers that you can assign to it. But there is a problem when you specify a number that is out of the range of the data type.

In that case, we will show you runtime error 6 overflow which indicates you need to change the data type and the number you have specified is out of the range.

Sửa lỗi run time error 13 type mismatch vba năm 2024

Other Situations When it Can Occurs

There might be some other situations in which you could face the runtime error 14: Type Mismatch.

  1. When you assign a range to an array but that range only consists of a single cell.
  2. When you define a variable as an object but by writing the code you specify a different object to that variable.
  3. When you specify a variable as a worksheet but use sheets collection in the code or vice versa.

How to Fix Type Mismatch (Error 13)

The best way to deal with this error is to use to go to the statement to run a specific line of code or show a message box to the user when the error occurs. But you can also check the court step by step before executing it. For this, you need to use VBA’s debug tool, or you can also use the shortcut key F8.

“Recently, I had created a macro for a file and at the first, it works fine. However, today when I opened and restarted the file, it throws an error message i.e., Microsoft Visual Basic Runtime Error 13 Type Mismatch in Excel. I did not change anything in the macro and I do not know why I am getting this error. Please, help!”

Are you acquiring the same error while running MS Excel and want to get rid of this? If yes, then, certainly you have landed on the right solution page. Here, we are going to discuss some simple and cost-efficient workarounds for the same. However, before going to the solution section, it is essential to know about the error message. So let us get started!

Sửa lỗi run time error 13 type mismatch vba năm 2024

A Brief Introduction to MS Excel Runtime Error 13

The runtime error 13 is a mismatch error that normally occurs when one or more data files or the required processes to launch an application, which by default uses the Visual Basic (VB) environment. When the user tries to run a VBA code that comprises data types, which are not matched properly the ms excel vba runtime error 13 type mismatch appears. Apart from this, there are many reasons that may generate this Excel error. This error displays as “run-time error 13 – Type mismatch”.

  • Runtime Error 13 occurs due to conflicts between the program and operating system
  • When a macro is clicked on by the user or a missing menu function from the Excel file
  • Corrupted/ damaged registry or incomplete installation of Microsoft Excel software
  • Virus or malware attack that corrupts the Excel related or Windows system files
  • Conflicts with other applications while launching a VBA Excel file also causes the error

Techniques to Fix MS Excel runtime error 13 Type Mismatch

Approach 1: Use Open and Repair Utility

To resolve the error code, users can utilize the Open and Repair tool to repair corrupted Excel file. It is an inbuilt utility to repair Excel files. Below are the guidelines for this:

  • Navigate to the File menu and click on Open
  • Now, choose the corrupt Excel file from the drop-down list of Open menu. Then, click on Open and Repair
  • Eventually, hit the Repair button

Note: The inbuilt repair utility cannot repair severely damaged Excel file. In such cases you can go for SysTools Excel Recovery Utility to resolve this issue.

Approach 2: Uninstall the Application

If you found that some software causes the Microsoft Visual Basic Runtime Error 13 Type Mismatch in Excel then, you can simply uninstall the problematic program to get rid of the error.

  • For this, first, navigate to Task Manager and stop the running applications
  • Now, go to the Start menu and choose Control Panel
  • Here, select Programs >> Uninstall a program
  • Doing this will display a list of installed programs on your computer
  • Select Microsoft Work from the menu list and click on Uninstall to remove this application from PC

Approach 3: Scan for Viruses or Malware

Virus and malware are one of the main cause to generate MS Excel Runtime Error 13 as they infect the user’s computer. If a malware or virus gets into the computer it not only replicates itself but, also corrupt the system files that may require to run certain applications of the computer. One can resolve the error via running a good antivirus program to detect the viruses and malware in PC.

Approach 4: Repair Windows Registry

Corruption in Windows registry files also may cause of this error message. Thus, follow the below-guidelines to fix Windows registry:

  • In your PC, search for Windows Registry

Sửa lỗi run time error 13 type mismatch vba năm 2024

  • In Windows registry editor open HKEY_LOCAL_MACHINE_Software
  • Click on Software and choose Microsoft >> Windows then, select Current version >> Run
  • Now, select the error file and Delete it
  • After this, reboot your system

Approach 5: Recover Missing Macros

Missing macros may occur the MS Excel Runtime Error 13 so, one can try to recover the missing Macros via following steps:

  • Open a new Excel file and set calculation mode to Manual
  • Click on Tools >> Macro >> Security >> High option
  • If you are using Excel 2007 then, click on Office >> Excel Options >> Trust Center
  • Now, click on Trust Center Settings >> Macros Settings. Here, choose Disable All Macros without Notification in Macro Settings and click on OK >> OK

Sửa lỗi run time error 13 type mismatch vba năm 2024

  • Open the corrupted workbook and if Excel opens it then, a message will appear that Macros are disabled
  • However, if Excel shut down then, this method is not working for you
  • Now, you have to press [Alt] + [F11] to open the Visual Basic Editor (VBE)
  • Use Project Explorer (press Ctrl+R keys) and hit a right-click on a module and Export File
  • Type a name and folder for a module and repeat this step as many times as you need to export the entire modules
  • Eventually, close the VBE and Exit

After this, open a new blank workbook or the recently created workbook, which contains recovered data from the corrupted workbook. Then, import the modules. This will resolve runtime error 13.

Concluding Lines

Microsoft Visual Basic Runtime Error 13 Type Mismatch in Excel is a commonly found Excel file error. In order to resolve this error, we have come up with this technical paper. Here, we have disclosed simple techniques to fix it. Now, it is all up to users that which solution they want to opt.

Sửa lỗi run time error 13 type mismatch vba năm 2024

By Ashwani Tiwari

Being a Chief Technical Analyst, I am aware of the technicalities faced by the user while working with multiple technologies. So, through my blogs and articles, I love to help all the users who face various challenges while dealing with technology.