جرب هذا التعديل
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.CountLarge > 1 Then GoTo 1
If Target.Row > 5 And Target.Column = 4 Then
Dim lr As Long, x As Long, y As Variant
y = Target.Value
lr = Cells(Rows.Count, Target.Column).End(xlUp).Row
x = Application.WorksheetFunction.CountIf(Range("D6:D" & lr), y)
If y < 1 Or y > 10 Or Not IsNumeric(y) Then MsgBox "Wrong Entry", vbExclamation: Exit Sub
If x > 50 Or y < 1 Or y > 10 Then _
MsgBox "The Number " & Target.Value & " Exceeds 50" & Chr(10) & _
"this number will be deleted", vbExclamation: Target = ""
End If
1:
Application.EnableEvents = True
End Sub