Error when executing an Excel macro to highlight rows and add comments

Copper Contributor

Hello everyone!

I'm encountering an issue while executing a macro in Excel that aims to highlight entire rows with a specific color and add a comment in the first cell of each highlighted row.

The macro successfully highlights the rows using the appropriate code. However, it fails to add the comment. Instead, I receive the following error message:

"Runtime Error '1004': Application-defined or object-defined error."

I have reviewed the code multiple times but haven't been able to pinpoint the exact cause of this error. I would greatly appreciate any assistance or suggestions in resolving this problem, allowing the macro to add comments in the first cell of each highlighted row successfully.

Thank you very much for your attention and support!

Regards!

1 Reply

@jacs03 

If you cannot be more specific than listing the error message, we probably need to get you up to speed on debugging VBA.  Study some articles like Debugging VBA Code and Excel VBA Debugging Techniques.

 

Do the debugging, and if the problem is not apparent, you should at least be able to show us the specific statement that causes the error.  (But we will probably need some context information as well, such as relevant variable definitions and values at the point of the error; expect more questions.)  Let us know which version of Excel you are using, on which platform (Windows or Mac), and in this case, which code libraries you are using (available from the References dialog).

 

Hopefully you are already including an "Option Explicit" statement at the top of each code module, and you are not trying to cram as much action into each line of code as you can.