Does anyone know how to add a comment to cell that has a validation list (ie a drop down list), in a protected sheet?
I have a simple routine that brings up an InputBox when the user double clicks on the cells that they want the comment in. This is attached to the BeforeDoubleClick event of the sheet. This works fine on all cells in an unprotected sheet.
For a protected sheet I have tried to add code to turn the protection off (and back on), but this only works for cells without a validation list! This is the code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim z As Variant
Application.CutCopyMode = False
ActiveSheet.Unprotect
If Selection.Column = 4 Or Selection.Column = 40 Then
z = InsertDate()
Else
z = InsertComment()
Cancel = True
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
—————————————————————————————————
Public Function InsertComment()
Dim myComment As String
Dim colnum As Integer
Dim rownum As Integer
Static ws2 As Worksheet
Set ws2 = ActiveSheet
rownum = Selection.row
colnum = Selection.Column
myComment = “”
If Range(Application.Names(“AppendComments”).Value).Value = True Then
On Error Resume Next
myComment = ActiveCell.Comment.Text ‘ Appends comment if true
End If
myComment = InputBox(“Input Comment”, “Add Comment”, myComment)
If Len(myComment) 0 Then
ActiveCell.ClearComments
ws2.Cells(rownum, colnum).AddComment.Text myComment
End If
End Function
————————————————————————————————-
One more bazaar thing. The cells I am attempting to add the comment to are formatted as NOT locked. However, if I select one of these NOT locked cells then double click on a locked cell I can add a comment TO THE NOT LOCKED CELL! Bazaar.
Any suggestions?