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
| Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error GoTo Err_Workbook_SheetChange
'Déclaration ===============================
Dim F_1 As Worksheet
Dim F_2 As Worksheet
Dim Plg As Range
Dim Cel As Range
'Validité ==================================
If (Sh.Name <> "A" And Sh.Name <> "B") Or _
Intersect(Target, [A1:E9]) Is Nothing _
Then GoTo Sort_Workbook_SheetChange
'MEI =======================================
Application.ScreenUpdating = False
Application.EnableEvents = False
Set F_1 = Sheets("A")
Set F_2 = Sheets("B")
Set Plg = Intersect(Target, [A1:E9])
'Traitement ================================
For Each Cel In Plg
If Sh.Name = F_1.Name Then
F_2.Range(Cel.Address) = Cel
Else
F_1.Range(Cel.Address) = Cel
End If
Next Cel
'Sortie obligatoire ========================
Sort_Workbook_SheetChange:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
'Traitement des erreurs =====================
Err_Workbook_SheetChange:
MsgBox Err.Description, vbCritical + vbOKOnly, "ERREUR n°" & Err.Number
Resume Sort_Workbook_SheetChange
End Sub |
Partager