Hello,
I know there's a way of doing it, but I'm failing continually.
I have this wonderful VBA that works brilliantly when the sheet is unprotected:
However, I would like to change it so that it can work on a protected sheet. I'm aware the code will need to unprotect, run, then protect again, but I can't seem to make it work. Please can you let me know how to modify the above VBA to do so.
Many thanks!
I know there's a way of doing it, but I'm failing continually.
I have this wonderful VBA that works brilliantly when the sheet is unprotected:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = False
On Error GoTo Exitsub 'Avoid On Error if not strictly necessary
If Not Intersect(Target, Range("N3:N163,O3:O163,P3:P163,Q3:Q163")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else
If Target.Value = "" Then
GoTo Exitsub
Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & "," & vbLf & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
End If
Exitsub:
On Error GoTo 0 ' linked to the on error above. Avoid On Error if not strictly necessary
Application.EnableEvents = True
End Sub
However, I would like to change it so that it can work on a protected sheet. I'm aware the code will need to unprotect, run, then protect again, but I can't seem to make it work. Please can you let me know how to modify the above VBA to do so.
Many thanks!