[Fixed!] Excel Application-Defined or Object-Defined Error in VBA

A runtime error in VBA is the 1004 error. It is also known as an application-defined or object-defined error in VBA. How come? since Excel only has a certain number of columns. We receive a 1004 error when our code instructs a device to move beyond its designated range. When we refer to a range that doesn’t exist in the sheet, we can also encounter this problem in other circumstances.

The above video shows that incorrect referencing in the code causes the error. Follow along to know about other reasons and solutions.


Application-Defined or Object-Defined Error (VBA Error 1004) in Excel

The VBA 1004 (object-defined error or an application-defined error) An error is a run-time error that happens while the code is being executed. Coding mistakes are inevitable, especially when writing for the first time. As a result, VBA may include several mistakes. Yet, this is a universal occurrence, thus it is of no great significance. But, being aware of the error that will result from it will help you prevent it in the future. In this article, we’ll talk about the object-defined error, or an application-defined error (“VBA 1004 Error”), one of the more significant Excel mistakes.


Excel Application-Defined or Object-Defined Error in VBA: 5 Possible Reasons with Solutions

The five most frequent causes of run time errors will be covered in this section, along with their respective solutions using VBA macros in Excel.


Reason 1: Incorrect Worksheet Name Causes Application-Defined or Object-Defined Error in Excel VBA

This mistake happens when renaming the sheet. whether the name of the worksheet is already in use. VBA throws a “Run-Time Error 1004” if you attempt to give another sheet the same name.

Application-Defined or Object-Defined Error in Excel VBA for Incorrect Name

  • Now, press F5 or click the Run button to execute the VBA macro.

Application-Defined or Object-Defined Error in VBA for incorrect name

  • Here, you will show an error with the sheet name.

Solution: Insert the Correct Worksheet Name

Therefore, we will rename the sheet here to avoid the Application-Defined or Object-Defined error in Excel VBA. You can see the correct VBA code in the below image.

Inserting Correct Worksheet Name

Read More: VBA Object Variable or with Block Variable Not Set in Excel


Reason 2: Incorrect Name Range of Object Causes Application-Defined or Object-Defined Error in Excel VBA

That typically happens when we attempt to access a named range in Excel that is misspelled or doesn’t exist, as in your case.

Application-Defined or Object-Defined Error in Excel VBA for Incorrect Name Range of Object

  • Now, press F5 or click the Run button to execute the VBA macro.

Showing Range of Object Error As Application-Defined or Object-Defined Error in Excel VBA

  • So, you can see the given error in the above image.

Solution: Correct the Misspelled Error

Here, we will correct the spelling to access a named range in the VBA code.

Correct the Misspelled Error

  • Therefore, you will see here that all the headings are selected with a named range called “Heading”.

Showing Name Range of Heading

Read More: [Fixed!] Subscript Out of Range Error in Excel VBA


Reason 3: Incorrect Referencing Causes Error in Excel VBA

You may have referenced an object wrongly in your code, which can also result in an error.

Incorrect Referencing As Application-Defined or Object-Defined Error in Excel VBA

  • Now, press F5 or click the Run button to execute the VBA macro.

Showing Application-defined or Object-defined Error for Incorrect Referencing

  • This will show you an error called“Range of object_Global”.

Solution: Use Correct Referencing

So, we will keep the reference correct to avoid this error.

Using correct Referencing to avoid application-defined or object-defined error in vba

  • Again, press F5 or click the Run button to execute the VBA macro.

Showing Final Output

  • Finally, you will get your result where you will paste the data in another range by correcting the reference.

Read More: Reasons And Solutions for Excel Object Required Error in VBA


Reason 4: Incorrect Workbook Name Causes Application-Defined or Object-Defined Error in Excel VBA

This error can also happen if an object is not discovered when opening a workbook. In this case, the workbook is the object that is not accessible.

Incorrect Workbook Name As Application-Defined or Object-Defined Error in Excel VBA 

  • Now, press F5 or click the Run button to execute the VBA macro.

Showing Application-Defined or Object-Defined Error in Excel VBA 

  • So, you will not find our Excel file here to activate.

Solution: Using Correct Filename with Extension

When encountering this issue, it’s crucial to double-check these components, including the file name, and file extension. Here, we will correct each of these parameters thoroughly in the VBA code.

Using Correct Filename with Extension 

Read More: How to Fix Compile Error in Hidden Module in Excel


Reason 5: Inactivated Worksheet Causes Error in Excel VBA

The primary cause of this problem is that the range of cells was activated without the worksheet first being activated.

Inactivate Worksheet Error As Application-Defined or Object-Defined Error in Excel VBA 

  • Now, press F5 or click the Run button to execute the VBA macro.

Showing Range of Class Failed Error As Application-Defined or Object-Defined Error in Excel VBA

  • Then, you will see theRange class error here in the above image.

Solution: Activate the Worksheet

We cannot activate the cells in the sheet without activating the sheet. Therefore, activate the sheet first, then activate its cells in the VBA code.

Activate the Worksheet with the Correct VBA Code

Read More: [Fixed!] Invalid Forward Reference in VBA


Frequently Asked Questions

1. How can I fix an Excel VBA Application-Defined or Object-Defined error?

The first step in fixing the run time problem is to try to locate the precise line of code that is to blame. Once you have located the line of code, you may examine it to see if the object or method being referenced has any problems. The code can then be changed if necessary to address the problem.

2. Can an issue with my machine or Excel installation produce an Application-Defined or Object-Defined error in Excel VBA?

Although it’s uncommon, a problem with your computer or Excel installation could be the root of the error in Excel VBA. The error is typically brought on by a problem with the code you wrote.


Download Practice Workbook

You may download the following Excel workbook for better understanding and practice it yourself.


Conclusion

In this article, we’ve covered five reasons for all possible application-defined or object-defined error in Excel VBA. We sincerely hope you enjoyed and learned a lot from this article. Additionally, if you want to read more articles on Excel, you may visit our website, Exceldemy. If you have any questions, comments, or recommendations, kindly leave them in the comment section below.


Related Articles:

Get FREE Advanced Excel Exercises with Solutions!
Bishawajit Chakraborty
Bishawajit Chakraborty

Bishawajit Chakraborty, a Rajshahi University of Engineering & Technology graduate with a B.Sc. in Mechanical Engineering, has been associated with ExcelDemy since 2022. Presently, he is a content developer, specializing in Excel Power Query, Data Analysis and VBA. It is worth mentioning that he has authored more than 90 articles on VBA content development. His profound interest lies in the fields of data analytics and data science. He possesses expertise in VBA, Power BI, machine learning, and Python... Read Full Bio

2 Comments
  1. i have a VBA application (available on “Contextures” as Excel Names Macro) which runs perfectly on a laptop with Office 10 but macro from this very same file if executed from a laptop with Office 365 gives this Run-time error ‘1004’: Application-defined or Object-defined error. What can be the reason ? (from: [email protected])

    • Hello KP MENON,

      Greetings! We appreciate you contacting us and commenting on our Excel blog post with your query. If the VBA code is not working properly in Office 365, you can provide the Excel file here. We will try our best to give the updated version of that VBA code compatible with Office 365. As ExcelDemy is currently providing the best solutions of Excel related problems, feel free to provide your problems in the blogpost.

      Moreover, in the following section, we have provided some troubleshooting options:

      1. When there is a problem with the Excel workbook or the VBA code being executed, the “Run-time error ‘1004’: Application-defined or Object-defined error” commonly occurs. 
      2. References that are either missing or broken could be the result of improperly installed external libraries or references on the laptop running Office 365. Make sure all necessary references are present and correctly selected by checking the VBA project’s references (in the VBA editor, choose “Tools” -> “References”). If any references are missing or are flagged as “MISSING,” you might need to update or reconfigure them to work with Office 365.
      3. Another possibility is that the problem is unique to the file or the environment in which it is being run. To see if the error still occurs, try running the VBA program with Office 365 on a different laptop. 

      You might need to give more information about the VBA code and the events that preceded the error to troubleshoot the specific error more thoroughly. Reviewing the specific line of code where the error appears can also shed light on where the problem originated.

      Regards

      Al Ikram Amit

      Team ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo