Hello,
I have been working on a simple calendar tracking spreadsheet which has many formulas and and other macros. Therefore, I must protect the file from accidental user deletions. There are some cells that are protected such that you can't even select them while others you can select but not edit.
That being said, there is a need to occasionally add comments to various cells from both types noted above. My biggest challenge has been working around the situation where someone clicks cancel at any time during the process (macro). I've already got the "delete comment" Macro working (shown below also for reference). I am having issues with the adding comments. I think there is obviously something going on after the first "end if", but I have not figured it out yet. Have a look and let me know your thoughts.
Code to delete comments: (seems to be working fine)
--------------------------------------
Sub Delete_Comment()Dim response1 As Range
On Error GoTo ErrorHandler
ActiveSheet.Unprotect
Set response1 = Application.InputBox(prompt:="Pick a cell.", Type:=8)
response1.Comment.Delete
ActiveSheet.Protect
End If
Exit Sub
ErrorHandler:
ActiveSheet.Protect
Exit Sub
End Sub
--------------------------------------------------------
Code to add comment: Not working so well
--------------------------------------------------------
Sub Comment()
Dim xselection As Range
Dim xcomment As String
On Error GoTo ErrorHandler
ActiveSheet.Unprotect
Set xselection = Application.InputBox(prompt:="Select a cell", Type:=8)
If xselection Is Nothing Then
End If
xTitleId = "Enter Comment"
xcomment = Application.InputBox("Input comments", xTitleId, "", Type:=2)
If xcomment = False Then
Else
xselection.AddComment
xselection.Comment.Text Text:=xcomment
ActiveSheet.Protect
End If
Exit Sub
ErrorHandler:
ActiveSheet.Protect
Exit Sub
End Sub
-----------------------------------------------------
I have been working on a simple calendar tracking spreadsheet which has many formulas and and other macros. Therefore, I must protect the file from accidental user deletions. There are some cells that are protected such that you can't even select them while others you can select but not edit.
That being said, there is a need to occasionally add comments to various cells from both types noted above. My biggest challenge has been working around the situation where someone clicks cancel at any time during the process (macro). I've already got the "delete comment" Macro working (shown below also for reference). I am having issues with the adding comments. I think there is obviously something going on after the first "end if", but I have not figured it out yet. Have a look and let me know your thoughts.
Code to delete comments: (seems to be working fine)
--------------------------------------
Sub Delete_Comment()Dim response1 As Range
On Error GoTo ErrorHandler
ActiveSheet.Unprotect
Set response1 = Application.InputBox(prompt:="Pick a cell.", Type:=8)
If response1 Is Nothing Then
ActiveSheet.Protect
Exit Sub
Elseresponse1.Comment.Delete
ActiveSheet.Protect
End If
Exit Sub
ErrorHandler:
ActiveSheet.Protect
Exit Sub
End Sub
--------------------------------------------------------
Code to add comment: Not working so well
--------------------------------------------------------
Sub Comment()
Dim xselection As Range
Dim xcomment As String
On Error GoTo ErrorHandler
ActiveSheet.Unprotect
Set xselection = Application.InputBox(prompt:="Select a cell", Type:=8)
If xselection Is Nothing Then
ActiveSheet.Protect
Exit Sub
ElseEnd If
xTitleId = "Enter Comment"
xcomment = Application.InputBox("Input comments", xTitleId, "", Type:=2)
If xcomment = False Then
ActiveSheet.Protect
Exit SubElse
xselection.AddComment
xselection.Comment.Text Text:=xcomment
ActiveSheet.Protect
End If
Exit Sub
ErrorHandler:
ActiveSheet.Protect
Exit Sub
End Sub
-----------------------------------------------------