Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a comment to a excel using VBA

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

like image 570
fydelio Avatar asked Feb 13 '15 07:02

fydelio


People also ask

How do I write a comment in VBA?

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.

How do I add a comment button in VBA?

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.


1 Answers

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
like image 196
BrakNicku Avatar answered Oct 20 '22 12:10

BrakNicku