I'm having real difficulties adding a comment to a cell.
I'm calling the following sub
Sub ValidationError(row As Long, column As Integer, ErrorLine As String)
Tabelle1.Cells(row, column).Interior.Color = vbYellow
Tabelle1.Cells(row, column).AddComment ErrorLine
End Sub
But I always get a 1004 error, saying "Application or object error" (this is translated, original message: "Anwendungs- oder objektdefinierter Fehler")
The sub is called using
Call ValidationError(8, 9, "Text string")
What am I doing wrong?
Best
VBA has the simplest way to convert a line of code into a comment. You simply need to place an apostrophe in front of the text you wish to turn into non-executable code, and the remaining text in that line will turn into a comment.
Step 1: Click on the line where you want to insert a comment. Step 2: Type an Apostrophe( ' ) at the start of a line. Step 3: Write the comment you want.
Your code should work if the target cell does not contain a comment. You can change the procedure to clear existing comments first:
Sub ValidationError(row As Long, column As Integer, ErrorLine As String)
Tabelle1.Cells(row, column).Interior.Color = vbYellow
Tabelle1.Cells(row, column).ClearComments
Tabelle1.Cells(row, column).AddComment ErrorLine
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With