problème sur Worksheet_Change

kinel

XLDnaute Occasionnel
Bonjour à tous
j'ai un souci sur le code suivant

sur la partie qui doit effacer automatiquement certaines cellules, si la cellule 4 est effacée il doit y avoir effacement automatique des cellules 3, 5, 6, 7, et 8
tout fonctionne bien sauf la 3 qui refuse de s'effacer

merci de votre aide
Kinel

Private Sub Worksheet_Change(ByVal Target As Range)
Dim flag As Boolean

'automatise la Majuscule sur le prénom
If Not Intersect(Target, Range("E3:E62")) Is Nothing Then
Application.EnableEvents = False
Target.Value = StrConv(Target, vbProperCase)
Application.EnableEvents = True
End If

'efface les infos si le nom est effacé
If Target.Column <> 4 Or Target.Count > 1 Or (Target.Row < 3 Or Target.Row > 62) Then Exit Sub
If IsEmpty(Target) Then

Application.EnableEvents = False
Target.Resize(, 3).ClearContents ' <<<<<<< ici
Target.Resize(, 5).ClearContents
Target.Resize(, 6).ClearContents
Target.Resize(, 7).ClearContents
Target.Resize(, 8).ClearContents
Application.EnableEvents = True
End If

'automatise le nom en MAJUSCULE
If Not Intersect(Target, Range("D3:D62")) Is Nothing Then
Application.EnableEvents = False
flag = True
Target.Value = Evaluate("PROPER(""" + Target.Value + """)")
Application.EnableEvents = True
End If

If Not Intersect(Target, Range("D3:D62")) Is Nothing Then
Application.EnableEvents = False
flag = True
Target.Value = UCase(Target.Value)
Application.EnableEvents = True
End If

End Sub

 

Si...

XLDnaute Barbatruc
Re : problème sur Worksheet_Change

salut

essayer
Code:
Application.EnableEvents = False
 Target.Offset(, -1).Resize(1, 6) = ""
Application.EnableEvents = True
au lieu de
Code:
Application.EnableEvents = False
Target.Resize(, 3).ClearContents ' <<<<<<< ici
Target.Resize(, 5).ClearContents
Target.Resize(, 6).ClearContents
Target.Resize(, 7).ClearContents
Target.Resize(, 8).ClearContents
Application.EnableEvents = True
 

mécano41

XLDnaute Accro
Re : problème sur Worksheet_Change

Bonjour à tous,

Essaie ce code qui devrait remplacer tout ce que tu as indiqué plus haut, sauf erreur de ma part...et si j'ai compris : effacer une cellule en amont et quatre en aval de la cellule effacée de D3 à D62.

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim flag As Boolean
If Target.Count > 1 Then Exit Sub
    Application.EnableEvents = False
If Not Intersect(Target, Range("E3:E62")) Is Nothing Then
    Target.Value = StrConv(Target, vbProperCase)
    If IsEmpty(Target) Then
        Target.Offset(0, -1).Resize(, 6).ClearContents
    End If
ElseIf Not Intersect(Target, Range("D3:D62")) Is Nothing Then
        flag = True
        Target.Value = Evaluate("PROPER(""" + Target.Value + """)")
        Target.Value = UCase(Target.Value)
End If
Application.EnableEvents = True
End Sub

Edit : je n'ai pas encore vu ton fichier

Cordialement
 

Pierrot93

XLDnaute Barbatruc
Re : problème sur Worksheet_Change

Re,
bonjour SI,

peut être aussi avec ceci :
Code:
    Application.EnableEvents = False
    Union(Cells(Target.Row, 3), Cells(Target.Row, 5).Resize(, 4)).ClearContents
    Application.EnableEvents = True

Edition : bonjour Mécano
 

Si...

XLDnaute Barbatruc
Re : problème sur Worksheet_Change

re

dans la même idée que mécano41 ;) (on dit bien, Pierrot93 ;), que l'Union...))
Code:
Private Sub Worksheet_Change(ByVal R As Range)
  If R.Count > 1 Then Exit Sub
  Application.EnableEvents = False
  If Not Intersect(R, [E3:E62].SpecialCells(2)) Is Nothing Then
    R = Application.Proper(R)
  End If
  If Not Intersect(R, [D3:D62]) Is Nothing Then
    R.Offset(0, -1).Resize(, 6).ClearContents
  End If
  Application.EnableEvents = True
End Sub
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 276
Messages
2 086 714
Membres
103 378
dernier inscrit
phdrouart