Adding Comments to Protected Worksheets

by Allen Wyatt
(last updated December 7, 2017)

12

Doug notes that Excel allows you to add comments to cells, but only if the worksheet is unprotected. He wonders if there is a way to allow the addition of comments in protected worksheets.

There are a few ways you can tackle this problem. The first is to simply modify how you protect your worksheet. Starting with an unprotected worksheet, follow these steps:

  1. Display the Home tab of the ribbon.
  2. In the Cells group, click Format | Protect Sheet. (You could also click the same tool on the Review tab of the ribbon.) Excel displays the Protect Sheet dialog box. (See Figure 1.)
  3. Figure 1. The Protect Sheet dialog box.

  4. Enter a password to be used in protecting the worksheet.
  5. Scroll down in the list of permissions and select the Edit Objects check box. (Comments are considered objects in Excel.)
  6. Set any other permissions desired.
  7. Click OK to dismiss the dialog box. If you provided a password in step 3 you are prompted to reenter it, which you should do.

Any worksheet user can now add comments to cells. Note that this allows them to add comments to any cells in the worksheet, not just to those cells that you've formatted as unlocked. In addition, users can also modify (add, change, or delete) any other objects in the worksheet, such as drawings and charts.

If you want a more granular approach to dealing with comments in protected worksheets, then you'll need to resort to using a macro. The concept is to have the macro prompt the user for the comment text, unlock the worksheet, insert the comment, and then relock the worksheet.

Public Sub InsertComment()
    Dim sPassword As String
    Dim MyComment As String

    sPassword = "123"

    Set commentCell = ActiveCell
    MyComment = InputBox("Enter your comments", "Comments")

    ActiveSheet.Unprotect Password:=sPassword
    Range(commentCell.Address).AddComment
    Range(commentCell.Address).Comment.Text Text:=MyComment
    ActiveSheet.Protect Password:=sPassword
End Sub

Change the value assigned to the sPassword variable; this is required to unlock and relock the worksheet. Since you are storing the password in the macro, you'll also want to make sure that you take steps to protect the macro (put a password on the VBA module) so others cannot see the password. The macro can be assigned to a shortcut key or added to the Quick Access Toolbar.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12928) applies to Microsoft Excel 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Understanding the At and Ln Indicators

Part of the helpful information that Word provides on the status bar is designated by the labels "At" and "Ln." Here's ...

Discover More

Creating Superscript and Subscript Buttons

Want a quick way to apply superscript and subscript to selected text within a cell? This tip shows how the formatting can ...

Discover More

Showing Filter Criteria on a Printout

When you print out a filtered worksheet, you may want some sort of printed record as to what filtering was applied to the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Changing the Comment Indicator Color

Add a comment to a worksheet, and you'll notice that Excel places a small, red triangle at the upper-right corner of the ...

Discover More

Viewing Comments

There are three different ways that Excel allows you to display any comments that are in your worksheet. Here's how you ...

Discover More

Placing Formula Results in a Comment

Excel won't allow you to directly or automatically insert the results of a formula into a cell's comment. You can, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 1?

2018-06-05 07:26:22

Excel Novice user

Thanks Steve, I've just personal messaged you via email.

Much obliged


2018-06-04 16:44:24

Steve.Jez

Novice,
You need to run the code module in order to display your input box. The best way, in my opinion is to add a button to the Quick Access Toolbar and make it only apply to this workbook, or you run the code from the macros button on the view tab (excel 365).

If you want to send me an email - click my name on my last post - I'll send you an excel file with some updated code to take care of errors & always make sure your worksheet always ends up locked.


2018-06-02 23:04:58

Excel Novice user

Thanks Steve.Jez, that's great.

One thing though, you mention the code works fine which is great to know it is okay. However, one query, as I couldn't get it to work..

Did you test it on a protected worksheet and if so how did you get the comment box to come up for you to add a comment and edit it? As when I write click I still don't see an option to add and edit comments when I'm in the protected sheet mode..

A heads up would be well appreciated.

Thanks in Advance!


2018-05-30 03:37:32

Steve.Jez

Sorry Novice,
When I read your last post on my phone it split your code onto different lines. Looking at it on a full screen it looks fine.
I've tested the Insert Comment code on a PC running office 365 & it works fine.

The following code all works on the same setup. A couple of tweaks which hopefully you can see. You'll need to change your password again.

Option Explicit:
Sub myAdd_myEdit_myDelete_Comment()
Dim myAdd, myEdit, myAE
Dim MyComment As String
Dim commentCell As Range
Dim myCheck
myAE = InputBox("If adding comment enter ""Add""" _
& vbCr & vbCr & _
"If editing comment enter ""Edit""" _
& vbCr & vbCr & _
"If Deleting comment enter ""Delete""", "Comments")

ActiveSheet.Unprotect Password:=123

If myAE = "Add" Then

Set commentCell = ActiveCell
MyComment = InputBox("Enter your Comment text...", "Comments")
If Not ActiveCell.Comment Is Nothing Then Exit Sub
Range(commentCell.Address).AddComment
Range(commentCell.Address).Comment.Text Text:=MyComment

ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your Comment NEW text...", "Comments")
ActiveCell.Comment.Text Text:=MyComment
ElseIf myAE = "Delete" Then
myCheck = MsgBox("Do you want to DELETE this Comment?", vbYesNo)
If myCheck = vbNo Then
GoTo lockup
Else
ActiveCell.Comment.Delete
End If

End If

lockup:
ActiveSheet.Protect Password:="123"
End Sub


Sub Comment_Be_Gone()

Dim rng As Range
Set rng = ActiveCell
If Not (rng.Comment Is Nothing) Then rng.Comment.Delete

End Sub

Sub Remove_All_Comments_From_Worksheet()

ActiveSheet.Unprotect Password:="123"

Cells.Select
Selection.ClearComments

ActiveSheet.Protect Password:="123"

End Sub


Good luck.


2018-05-29 06:23:44

Excel Novice user

Thanks Jez, could you repost the correct coding that you mean? I'm having difficulty finding / figuring out the 'exact' sections you mean.


2018-05-28 04:48:00

Steve.Jez

Novice user,
It looks like you have split the code at Text = Mycomment it should be on the same line as the line above.
And ditto for password:=spassword

If you copy Allens code from above & just change the password it should all work.

HTH


2018-05-27 02:31:33

Excel Novice user

Hello,

I have tried the above coding to insert comments on a protected cell and it did not work for me...

Here is another set of coding that is said to work but it doesn't work for me, can someone help me with coding for inserting comments on protected sheets please?


Example coding below that I have tried, plus a link to my spreadsheet that will expire in 7 days... Please phelp by proving the correct coding that I can copy and paste to my worksheet VBA please, as I am a novice user having some difficulty with this.

https://we.tl/qQqM0NpOaB


CODING EXAMPLES I HAVE TRIED THAT DOES NOT WORK FOR SOME REASON???

INSERT COMMENT CODE:


Public Sub InsertComment()
Dim sPassword As String
Dim MyComment As String

sPassword = "Ankh7mind"

Set commentCell = ActiveCell
MyComment = InputBox("Enter your comments", "Comments")

ActiveSheet.Unprotect Password:=sPassword
Range(commentCell.Address).AddComment
Range(commentCell.Address).Comment.Text Text:=MyComment
ActiveSheet.Protect Password:=sPassword
End Sub



EDIT, ADD, DELETE CODE:


Option Explicit:
Sub myAdd_myEdit_myDelete_Comment()
Dim myAdd, myEdit, myAE
Dim MyComment As String
Dim commentCell As Range
Dim myCheck
myAE = InputBox("If adding comment enter ""Add""" _
& vbCr & vbCr & _
"If editing comment enter ""Edit""" _
& vbCr & vbCr & _
"If Deleting comment enter ""Delete""", "Comments")
If myAE = "Add" Then
ActiveSheet.Unprotect Password:=Ankh7mind
Set commentCell = ActiveCell
MyComment = InputBox("Enter your Comment text...", "Comments")
If Not ActiveCell.Comment Is Nothing Then Exit Sub
Range(commentCell.Address).AddComment
Range(commentCell.Address).Comment.Text Text:=MyComment
ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your Comment NEW text...", "Comments")
ActiveCell.Comment.Text Text:=MyComment
ElseIf myAE = "Delete" Then
myCheck = MsgBox("Do you want to DELETE this Comment?", vbYesNo)
If myCheck = vbNo Then
Exit Sub
Else
ActiveCell.Comment.Delete
End If
ActiveSheet.Protect Password:=Ankh7mind
End If
End Sub


REMOVE CODE:
Sub Comment_Be_Gone()
Dim rng As Range
Set rng = ActiveCell
If Not (rng.Comment Is Nothing) Then rng.Comment.Delete
End Sub
Sub Remove_All_Comments_From_Worksheet()
Cells.ClearComments
End Sub






2014-10-13 10:23:59

Aline

1. I have a file with (password) protected sheets.
2. The data entry is restricted to a few cells
3. During the calculation I can run various macros (e.g. show and hide columns and rows, create new sheets with the same layout and cell protection etc)

I did as you described under point(s) 1. till 4. and now I have the problem that as soon as I run other macros in my file they seem to "overrule" this setting and I can no longer insert comments.

What I want/need is a macro (allows comments) that runs automatically when I open the workbook and which is not affected by other macros...


2014-06-06 19:16:11

Scott

That macro works to enter a new comment but what would the macro be to edit an existing comment? Thanks for the help.


2014-02-04 13:47:36

Don

My rationale for whether to allow people to select or not select cells has to do with whether there is sensitive information on the worksheet that should not be copied to some other document. Examples are financials during blackout period and some personnel data.

If there is no sensitive data then I let them select, copy, and paste elsewhere.

Excel already provides a general message that the data is not editable, so that is covered to some extent.

I've never had the need to intercept that message in order to replace it with something more context sensitive, nor do I see the opportunity in the Event lists for worksheets and workbooks presented by the VBE.


2014-02-03 08:03:15

Bryan

Andrew: why not? I'm kind of OCD about where my cursor is, and I like to scroll around using the arrow keys, which is jarring if you have protected cells. I can see an argument that users might get confused and wouldn't be able to figure out why they can't edit the cells, but I think this can be sorted through clarity of formatting and labels.


2014-02-03 04:23:53

Andrew

I never allow people to select locked cells in a protected workbook. Why do they need to select cells you do not want them to edit?
A couple of other useful options to tick is to allow sort and autofilter.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.