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 36 37 38 39 40 41 42 43 44 45
| Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error GoTo Err_Workbook_SheetChange
'Déclaration ==============================
Dim F As Worksheet
Dim Cel As Range
Dim Plg As Range
Dim Tab_v()
Dim X As Long
Dim Y As Long
'MEI ======================================
Application.ScreenUpdating = False
Application.EnableEvents = False
If Intersect(Target, Columns(3)) Is Nothing Then GoTo Sort_Workbook_SheetChange
Set Plg = Intersect(Target, Columns(3))
'détermination des modifs =================
ReDim Tab_v(1 To 2, 1 To Plg.Cells.Count)
For X = 1 To UBound(Tab_v, 2)
Tab_v(1, X) = Plg.Cells(X).Offset(0, -2)
Tab_v(2, X) = Plg.Cells(X)
Next X
'traitement ===============================
For Each F In ThisWorkbook.Sheets
For X = 1 To UBound(Tab_v, 2)
For Y = 1 To F.Range("A65536").End(xlUp).Row
If F.Range("A" & Y) = Tab_v(1, X) Then
F.Range("C" & Y) = Tab_v(2, X)
Exit For
End If
Next Y
Next X
Next F
'Sortie obligatoire =======================
Sort_Workbook_SheetChange:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
'Gestion des erreurs ======================
Err_Workbook_SheetChange:
MsgBox Err.Description, vbCritical + vbOKOnly, "ERREUR n°" & Err.Number
Resume Sort_Workbook_SheetChange
End Sub
Sub test()
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub |
Partager