Validation de données selon deux conditions
Bonsoir à tous,
Malgré mes recherches, je n'arrive pas à solutionner mon problème qui suit :
Dans une colonne, j'aimerai empêcher la saisie de date non comprise dans l'année en cours ou la saisie de texte sauf le mot "ANNULEE".
J'ai essayé le code suivant sans résultat ("erreur 1004") :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M3:M1500")) Is Nothing Then
If IsDate(ActiveCell.Value) Then
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=DATE(YEAR(NOW()),1,1", Formula2:= _
"=DATE(YEAR(NOW()),12,31"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Attention !"
.InputMessage = ""
.ErrorMessage = "Vous devez obligatoirement saisir une date comprise dans l'année en cours !"
.ShowInput = False
.ShowError = True
End With
Else
If Target.Value Like "ANNULE*" Then
'rien
ElseIf Not Target.Value Like "ANNULE*" And Target.Value Like "*" Then
With Selection.Validation
.Delete
.Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="<>""ANNULE*"""
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Attention !"
.InputMessage = ""
.ErrorMessage = "Vous devez obligatoirement saisir le mot ANNULEE !"
.ShowInput = False
.ShowError = True
End With
End If
End If
End If
End Sub |
Comme je ne suis pas un grand autodidacte, je vous remercie d'avance de me dire où je me plante. :(
Cordialement.