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
| Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Worksheet_Change
Dim Cel As Range, Plage As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
'Bloquer la gestion des évènements
Set Plage = Intersect(Target, Range([L1], Cells(Rows.Count, "L").End(xlUp)))
'plage = cellules appartenant à la colonne L ayant été modifiées
If Plage Is Nothing Then GoTo Sortie_Worksheet_Change
'si plage est vide, aller à la sortie
For Each Cel In Plage
'Pour chaque cellules modiifées de L
If IsEmpty(Cel) Then
Cel.Offset(0, 1).ClearContents
'Effacer la cellule à sa droite
Else 'cel n'est pas vide
If IsEmpty(Cel.Offset(0, 1)) Then Cel.ClearContents
'si la cellule M est vide alors, effacer L
MsgBox "remplir d'abord la cellule en " & Cel.Offset(0, 1).Address
End If
Next Cel
'Cellule suivante
Sortie_Worksheet_Change:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
Err_Worksheet_Change:
MsgBox Err.Description, vbCritical + vbOKOnly, "Erreur n°" & Err.Number
Resume Sortie_Worksheet_Change
End Sub |
Partager