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 46 47 48 49 50 51 52 53 54 55 56 57 58
| Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 31 And Target.Cells.Count = 1 Then '(Target.Count = 1 le fait aussi)
ActiveSheet.Unprotect Password:="TEST"
Dim sheetTemp As Worksheet
Dim sheetToPaste As Worksheet
Dim sheetToPaste2 As Worksheet
Dim rng As Range
If Target <> "" Then
Range("J" & Target.Row).Value = Now()
Application.Union(Range("A" & Target.Row & ":E" & Target.Row), Range("J" & Target.Row & ":J" & Target.Row), Range("X" & Target.Row & ":X" & Target.Row), Range("AD" & Target.Row & ":AE" & Target.Row), Range("AG" & Target.Row & ":AN" & Target.Row)).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Set sheetTemp = ActiveSheet
Set sheetToPaste = Worksheets("Feuil1")
sheetToPaste.Activate
lastRow = sheetToPaste.Columns(1).Find(What:="*", SearchDirection:=xlPrevious).Row
sheetToPaste.Range("A" & lastRow + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Set rng = sheetToPaste.Range("A2", "Q" & lastRow + 2)
rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), Header:=xlNo
sheetTemp.Activate
Range("a" & Target.Row).Resize(1, 40).Locked = True
Else
Range("a" & Target.Row).Resize(1, 40).Locked = False
End If
ElseIf Target.Column = 32 And Target.Cells.Count = 1 Then
ActiveSheet.Unprotect Password:="TEST"
Dim sheetTemp As Worksheet
Dim sheetToPaste As Worksheet
Dim sheetToPaste2 As Worksheet
Dim rng As Range
If Target <> "" Then
Range("J" & Target.Row).Value = Now()
Application.Union(Range("A" & Target.Row & ":E" & Target.Row), Range("J" & Target.Row & ":J" & Target.Row), Range("X" & Target.Row & ":X" & Target.Row), Range("AD" & Target.Row & ":AE" & Target.Row), Range("AG" & Target.Row & ":AN" & Target.Row)).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Set sheetTemp = ActiveSheet
Set sheetToPaste = Worksheets("Feuil2")
sheetToPaste.Activate
lastRow = sheetToPaste.Columns(1).Find(What:="*", SearchDirection:=xlPrevious).Row
sheetToPaste.Range("A" & lastRow + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Set rng = sheetToPaste.Range("A2", "Q" & lastRow + 2)
rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), Header:=xlNo
sheetTemp.Activate
Range("a" & Target.Row).Resize(1, 40).Locked = True
Else
Range("a" & Target.Row).Resize(1, 40).Locked = False
End If
Sheets("Base").Protect Password:="TEST"
Sheets("Feuil1").Protect Password:="TEST"
Sheets("Feuil2").Protect Password:="TEST"
End Sub |
Partager