I have several cells that use vlookup to insert values based on a selection from a dropdown in a different cell. I locked the cells with the formulas and protect the sheet to preserve unintended formula corruption. However, when I protect the sheet, VB code that allows multiple values in a handful of unrelated cells stops working. I have very little VB knowledge/experience. Here is the code for multiple values:
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Column = 13 Or Target.Column = 8 Or Target.Column = 14 Or Target.Column = 15 Or Target.Column = 18 Or Target.Column = 21 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 & vbNewLine & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
Cells.Replace What:=Chr(10), Replacement:=";", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
I used to have Activsheet.Unprotect in the beginning, and Activesheet.protect at the end, but I removed it because users had to keep unprotecting the sheet too many times and it was both frustrating and unproductive.
Thank you in advance.
Regards,
Nick
Bookmarks