MarcBeideler
New Member
- Joined
- Jan 26, 2021
- Messages
- 11
- Office Version
- 2016
- Platform
- Windows
Hello,
I've a problem with my Code.
Everything worked well till I had to insert another condition, which is the last "If Not Intersect" in my code below.
Maybe anyone could help me to make it work
I've a problem with my Code.
Everything worked well till I had to insert another condition, which is the last "If Not Intersect" in my code below.
Maybe anyone could help me to make it work
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Dim ws As Worksheet
If Not Intersect(Target, Range("N5:Q405")) Is Nothing Then
For Each c In Target
If c.comment Is Nothing And c.Value <> "" Then
Sheet1.Unprotect Password:="pbmi1327"
With c.AddComment
.Visible = False
.Text Application.UserName & " - " & Date & " - " & Time & " - " & c.Value
c.comment.Shape.TextFrame.AutoSize = True
Sheet1.Protect DrawingObjects:=True, Contents:=True, AllowFormattingCells:=False, Scenarios:=True, Password:="pbmi1327"
End With
ElseIf c.comment Is Nothing And c.Value = "" Then
Sheet1.Unprotect Password:="pbmi1327"
With c.AddComment
.Visible = False
.Text Application.UserName & " - " & Date & " - " & Time & " - " & "Deleted"
c.comment.Shape.TextFrame.AutoSize = True
Sheet1.Protect DrawingObjects:=True, Contents:=True, AllowFormattingCells:=False, Scenarios:=True, Password:="pbmi1327"
End With
ElseIf Not c.comment Is Nothing And c.Value <> "" Or c.Value = "" Then
Sheet1.Unprotect Password:="pbmi1327"
c.comment.Text Application.UserName & " - " & Date & " - " & Time & " - " & c.Value & vbNewLine & c.comment.Text
c.comment.Shape.TextFrame.AutoSize = True
Sheet1.Protect DrawingObjects:=True, Contents:=True, AllowFormattingCells:=False, Scenarios:=True, Password:="pbmi1327"
End If
If Not Intersect(Target, Range("AC5")) Is Nothing Then
Target.Copy
Sheet1.Range("C5:C405" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End If
Next
End If
End Sub
Last edited by a moderator: