VBA "Compile Error Expected: end of statement"

Hello Team VBA,

Could someone help me please with a problem inserting multi-line text from the VBE into a comment object on a worksheet.

Excel 2003
Windows XP

Please proceed to the text statement below for description of the problem.

With Sheets("Sheet27").Range("A10").AddComment .Text "This is text that should be inserted into a comment. _  Trouble is the vba editor wont accept these "space underscores" _ which i use normally to break up my code for easier reading. What _ is going wrong? I can see its got something to do with the quote marks _ but i need the quote marks for the comment text to work. It doesnt like _ putting text in quotes on each line and using an ampesand (&) to string together."
End With

I get a compile error and the text turns red.

What am i doing wrong and where could i have found the solution for myself without going to the microsoft forum

Many thanks team VBA.
You can do this with a line feed:

With Sheets("Sheet1").Range("A1").AddComment
    .Text "This is text that should be inserted into a comment." & vbLf & "This is a new line."
End With


4 people were helped by this reply


Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.


Question Info

Last updated June 5, 2020 Views 16,090 Applies to: