Hi,
I have the following code to insert a comment into a protected workbook which works fine, what I would like to do is modify it so that it will only allow the user to enter a comment in the following range instead of any cell on the sheet.
Range ("J8:DM5038")
Regards,
I have the following code to insert a comment into a protected workbook which works fine, what I would like to do is modify it so that it will only allow the user to enter a comment in the following range instead of any cell on the sheet.
Range ("J8:DM5038")
Code:
Sub InsertComment()
Dim xCom As String
Dim User As String
Dim xName As String
Dim Rng As Range
Dim c As Range
Set Rng = Sheet2.Range(Sheet2.Range("E6"), Sheet2.Range("E" & Rows.Count).End(xlUp))
User = UCase(Environ("username"))
If ActiveCell.Comment Is Nothing Then 'Checks to see if the cell already has a comment
For Each c In Rng
If UCase(c) = User Then xName = c.Offset(, -2)
Next c
xTitleId = "Add Comment"
xCom = Application.InputBox("Enter comment", xTitleId, "", Type:=2)
With Application
.ActiveSheet.Unprotect Password:="staff"
.ActiveCell.AddComment
.ActiveCell.Comment.Text Text:=xName & ":" & Chr(10) & xCom
.ActiveSheet.Protect Password:="staff"
End With
Else
ActiveCell.Comment.Delete
For Each c In Rng
If UCase(c) = User Then xName = c.Offset(, -2)
Next c
xTitleId = "Add Comment"
xCom = Application.InputBox("Enter comment", xTitleId, "", Type:=2)
With Application
.ActiveSheet.Unprotect Password:="password"
.ActiveCell.AddComment
.ActiveCell.Comment.Text Text:=xName & ":" & Chr(10) & xCom
.ActiveSheet.Protect Password:="password"
End With
End If
End Sub
Regards,