{"id":2907,"date":"2018-08-11T09:47:43","date_gmt":"2018-08-11T09:47:43","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=2907"},"modified":"2024-03-29T15:48:43","modified_gmt":"2024-03-29T15:48:43","slug":"vba-runtime-error-1004-application-defined-or-object-defined-error","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/vba-runtime-error-1004-application-defined-or-object-defined-error\/","title":{"rendered":"VBA Runtime Error 1004 \u201cApplication-defined or Object-defined error\u201d"},"content":{"rendered":"\n
The VBA Runtime Error 1004 can be caused by many things. In this article, I\u2019ll show a few different situations and how to deal with them.<\/p>\n\n\n\n
This code usually happens when VBA code refers to a cell or range that doesn\u2019t exist. For example, this code is correct.<\/p>\n\n\n\n
Sub myFunc()\n Set Rng = Worksheets(\"Sheet1\").Range(\"Z3\")\n Set Rng2 = Worksheets(\"Sheet1\").Range(\"ZZ3\")\nEnd Sub<\/pre>\n\n\n\nBut when you try to access the following ranges, the program will return an error in both cases.<\/p>\n\n\n\n
Sub myFunc()\n 'Error 1004 \"Application-defined or Object-defined error\"\n Set Rng = Worksheets(\"Sheet1\").Range(\"ZZZ3\")\n Set Rng2 = Worksheets(\"Sheet1\").Range(\"myRange\")\nEnd Sub<\/pre>\n\n\n\n