Autres (RESOLU) effacer une cellule par autre cellule

chaelie2015

XLDnaute Accro
Bonsoir forum
je souhaite effacer une cellule E4 (fusionné) si je saisi dans une autre cellule K4 (fusionné) et vis versa.
si je saisi dans la cellule E4 alors effacer K4

Private Sub Worksheet_Change(ByVal Target As Range) ' Efface E4 quand K4 change
If Not Application.Intersect(Target, Range("K4")) Is Nothing Then
Range("E4") = " "
End If
End Sub

merci
 

Pièces jointes

  • Charlie test effacer par cellule.xlsm
    14.3 KB · Affichages: 12
Dernière édition:

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonsoir Chaelie,
En mettant les deux conditions à la suite.
Les "Application.EnableEvents " évitent la ré entrance quand on va effacer l'autre cellules pour éviter de se ré-appeler.
VB:
Private Sub Worksheet_Change(ByVal Target As Range) ' Efface les produits quand HW/SW change
If Not Application.Intersect(Target, Range("K4")) Is Nothing Then
    Application.EnableEvents = False
    Range("E4") = " "
End If
If Not Application.Intersect(Target, Range("E4")) Is Nothing Then
    Application.EnableEvents = False
    Range("K4") = " "
End If
Application.EnableEvents = True
End Sub
 

Pièces jointes

  • Charlie test effacer par cellule.xlsm
    13.4 KB · Affichages: 5

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bonsoir,
Peut-être comme ça :
VB:
Private Sub Worksheet_Change(ByVal Target As Range) ' Efface les produits quand HW/SW change
If Not Application.Intersect(Target, Range("e4")) Is Nothing Then
    If Target <> "" Then
    [k4] = ""
    End If
End If
If Not Application.Intersect(Target, Range("k4")) Is Nothing Then
    If Target <> "" Then
    [e4] = ""
    End If
End If
End Sub
Fichier joint,
lionel :)
 

Pièces jointes

  • Charlie test effacer par cellule.xlsm
    14.6 KB · Affichages: 3

soan

XLDnaute Barbatruc
Inactif
Bonsoir @chaelie2015, sylvanu, lionel,

ton fichier en retour. :) code VBA du module de Feuil1 :

VB:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range) ' Efface les produits quand HW/SW change
  With Target
    If .CountLarge > 1 Then Exit Sub
    If .Value = "" Then Exit Sub
    If .Address = "$E$4" Then [K4:M4].ClearContents Else _
      If .Address = "$K$4" Then [E4:G4].ClearContents
  End With
End Sub

j'ai supprimé ton Module1 inutile. 😜

soan
 

Pièces jointes

  • Charlie test effacer par cellule.xlsm
    13.3 KB · Affichages: 4

chaelie2015

XLDnaute Accro
Bonsoir @chaelie2015, sylvanu, lionel,

ton fichier en retour. :) code VBA du module de Feuil1 :

VB:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range) ' Efface les produits quand HW/SW change
  With Target
    If .CountLarge > 1 Then Exit Sub
    If .Value = "" Then Exit Sub
    If .Address = "$E$4" Then [K4:M4].ClearContents Else _
      If .Address = "$K$4" Then [E4:G4].ClearContents
  End With
End Sub

j'ai supprimé ton Module1 inutile. 😜

soan
Bonsoir SOAN
Désolé je n’ai pas vu ta réponse a temps
Merci
 

laurent950

XLDnaute Accro
Bonsoir le forum
une variante de plus
VB:
Private Sub Worksheet_Change(ByVal Target As Range) ' Efface les produits quand HW/SW change
If Target(, 1) = Empty Then Exit Sub
Dim Rgn1, Rgn2 As Range
If Target = [E4] Then Set Rgn1 = Target: Set Rgn2 = [K4] Else Set Rgn1 = [E4]: Set Rgn2 = Target
If Rgn1 = Target Then
    Rgn2.MergeArea.ClearContents
Else
    Rgn1.MergeArea.ClearContents
End If
End Sub
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 195
Messages
2 086 082
Membres
103 112
dernier inscrit
cuq-laet