A friend helped me with this code who is out of pocket now and maybe someone on here can help. The code was working fine until I noticed it was deleting formulas. The formulas being deleted are in protected cells out of the range the code is running in e.g. E3:E9. I'm assuming it has something to do with: Sheets("DataEntry").Protect UserInterfaceOnly:=True ??? I thought that statement would allow changes to the sheet without effecting the formulas? Here's the code:
thx for any help
Code:
Dim LR, i As Long, cellsToFill As Range
If Intersect(Target, Range("$Q$11:$Q$399")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
i = Target.Row
Application.EnableEvents = False
Application.ScreenUpdating = False
Sheets("DataEntry").Protect UserInterfaceOnly:=True
If Target.Value = "" And Target.Interior.ColorIndex = 36 Then
MsgBox "This record was previously copied" & vbLf & _
"to another worksheet." & vbLf & vbLf & _
"If you are going to delete it, remember" & vbLf & _
"to delete in the another worksheet too."
Target.Interior.ColorIndex = 3
GoTo getout
End If
Set cellsToFill = Union(Cells(i, 2), Cells(i, 3), Cells(i, 4))
If Target.Value = "" Then GoTo getout
If Application.CountA(cellsToFill) < 3 Then
CreateObject("WScript.shell").popup _
"please, fill all the required cells" & vbLf & vbLf & _
"data will not be copied", 3, "hello"
Target.Value = ""
GoTo getout
Else: Target.Interior.ColorIndex = 36
Target.Offset(, -15).Resize(, 14).Copy
Select Case UCase(Target.Value)
Case [S4]
With Sheets("MGR2")
LR = .Cells(199, 2).End(xlUp).Row
.Cells(LR + 1, 2).PasteSpecial
End With
MsgBox "the record was pasted into MGR2 sheet"
Case [S5]
With Sheets("MGR3")
LR = .Cells(199, 2).End(xlUp).Row
.Cells(LR + 1, 2).PasteSpecial
End With
MsgBox "the record was pasted into MGR3 sheet"
Case [S3]
With Sheets("MGR1")
LR = .Cells(199, 2).End(xlUp).Row
.Cells(LR + 1, 2).PasteSpecial
End With
MsgBox "the record was pasted into MGR1 sheet"
Case [S6]
With Sheets("MGR4")
LR = .Cells(199, 2).End(xlUp).Row
.Cells(LR + 1, 2).PasteSpecial
End With
MsgBox "the record was pasted into MGR4 sheet"
Case Else
Target.ClearContents
Target.Interior.ColorIndex = xlNone
End Select
Target.Value = UCase(Target.Value)
End If
Application.CutCopyMode = False
Application.ScreenUpdating = True
getout:
Application.EnableEvents = True
End Sub