Please try the amendment below
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim Cell As Range
Select Case Sh.Name
Case "Rota", "Rota (2)"
Application.EnableEvents = False
Target.Parent.Unprotect
On Error GoTo NoComments
For Each Cell In Cells.SpecialCells(xlCellTypeComments)
Cell.Comment.Delete
Next Cell
NoComments:
For Each Cell In Target
If Intersect(Range("B6:N12"), Cell) Is Nothing = False Or Intersect(Range("B15:N21"), Cell) Is Nothing = False Then
If Cell.Value <> "" And Cell.Value <> "D/O" And Cell.Value <> "HOLS" And Cell.Value <> "150" Then
If HasComment(Cell) = False Then
Cell.AddComment
End If
Cell.Comment.Text Cell.Value
Cell.Comment.Visible = True
End If
End If
Next Cell
Target.Parent.Protect
Application.EnableEvents = True
End Select
End Sub
Function HasComment(Cell As Range) As Boolean
HasComment = False
On Error GoTo NoCommentFound
X = Cell.Comment.Text
HasComment = True
On Error GoTo 0
Exit Function
NoCommentFound:
End Function
Bookmarks