Interdire cellule E8 si E3 est renseigné et inversement

Bonjour le forum

La demande est dans le titre

Merci à vous

PS: Excel 2003

Bonjour,

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
    If Not Intersect(Target, Union(Range("E3"), Range("E8"))) Is Nothing Then
        x = Range("E3").Value
        y = Range("E8").Value
        If (x <> "") And (y <> "") Then Application.Undo
    End If
Application.EnableEvents = True

End Sub
9e3e8.xlsm (11.92 Ko)

Bonjour,

Voici une proposition, avec décalage automatique sur la cellule du dessous :

'code a mettre sur le module de la feuille concernée
Private sub worksheet_selectionchange(byval target as range)

If not range("E3").value <> "" and not range("E3").value <> "" then

'interdiction E8
if not intersect(target, range("E8")) is nothing then
    if range("E3").value <> "" then
        Call Interdire(target)
    end if
end if

'interdiction E3
if not intersect(target, range("E3")) is nothing then
    if range("E8").value <> "" then
        Call Interdire(target)
    end if
end if

End if

End sub

'code à mettre dans un module normal
Sub Interdire(Cible as range)
Cible.offset(1,0).activate 'décalage vers la cellule de dessous
End sub

Cdlt,

Edit : Salut Steelson

Bonjour Steelson & 3GB

Merci à vous les 2

Celle de Steelson fonctionne nickel et très simple

3GB je regarde la tienne

C'est résolu

Bonne fin de WE à vous deux

Cordialement

Bonjour,

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
    If Not Intersect(Target, Union(Range("E3"), Range("E8"))) Is Nothing Then
        x = Range("E3").Value
        y = Range("E8").Value
        If (x <> "") And (y <> "") Then Application.Undo
    End If
Application.EnableEvents = True

End Sub
9e3e8.xlsm (11.92 Ko)

Bonsoir Steelson

Ça fonctionne super bien mais je voudrais ajouter si c'est possible

Ajouter un message comme "Saisie Impossible" dans E3 ou E8

Si pas possible ne s'escrime pas

Merci

Bonne fin de soirée

à adapter si besoin

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
    If Not Intersect(Target, Union(Range("E3"), Range("E8"))) Is Nothing Then
        x = Range("E3").Value
        y = Range("E8").Value
        If (x <> "") And (y <> "") Then
            Application.Undo
            MsgBox "Modification impossible !"
        End If
    End If
Application.EnableEvents = True

End Sub

Bonsoir Steelson

SUPER.

Merci

Bonne fin de soirée

Bonjour à tous,

J'ai rien compris et une simple validation ne suffit pas ?
Formule de validation : =NBVAL($E$3;$E$8)=1
Avec éventuellement un message dans les onglets Saisie et/ou Erreur

Vieux motard que jamais

7classeur1.xlsx (8.69 Ko)

eric

11classeur1.xls (26.50 Ko)

J'ai rien compris et une simple validation ne suffit pas ?

Superbe Eriiiic, je ne connaissais pas ! pftt, que c'est simple !

Rechercher des sujets similaires à "interdire renseigne inversement"