An implementation of Visual Basic that is built into Microsoft products.
Hi @Malay Saysana ,
Thanks for reaching out.
From what you described, the ‘1004: Application-defined or Object-defined error’ usually happens when Excel can’t find or use something your macro is referencing - like a sheet, a range of cells, or a named object. In other words, your code is trying to tell Excel to do something, but Excel doesn’t know exactly what you mean.
A few common causes and ways to fix it:
- Make sure the sheet you’re referencing actually exists and the cell or range is correct. Even a small typo can cause this error.
- When using
RangeorCells, make sure to specify which worksheet it belongs to. For example:With Worksheets("Sheet1") .Range("A1:A10").Select End With - If the sheet is protected, Excel won’t let the macro make changes. You may need to unprotect it first:
Worksheets("Sheet1").Unprotect "yourpassword" - Ensure you’re not trying to access a cell or column that doesn’t exist (Excel’s last column is XFD).
A good approach is to enable debugging in VBA so you can see exactly which line is causing the error. Once you know that, it’s usually a simple matter of correcting the sheet, range, or object reference.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.