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
| Sub MoveData()
Dim cell_ori As Range
Dim cell_des As Range
Dim nom(1 To 12) As String
Dim chemin As String
nom(1) = "fichier collaborateur 1"
nom(2) = "fichier collaborateur 2"
'nom(3) =
'nom(4) =
'nom(5) =
'nom(6) =
'nom(7) =
'nom(8) =
'nom(9) =
'nom(10) =
'nom(11) =
'nom(12) =
With Worksheets("Feuil1")
For dossier = 1 To 12
'Set le chemin du dossier d'origine
chemin = "C:\...\" & nom(dossier) & ".xlsx"
'Open the destination workbook
On Error Resume Next
Set Wk = Workbooks(nom(dossier))
If Err <> 0 Then
Err = 0
'MsgBox "Ce fichier est fermé"
Workbooks.Open chemin
Else
'MsgBox "Ce fichier est ouvert"
End If
For i = 1 To .Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
Set cell_des = .Range("A1").Offset(i, 0)
Set cell_ori = Workbooks(nom(dossier)).Worksheets("Feuil1").Range("V:V").Find(cell_des.Value, LookIn:=xlFormulas, lookat:=xlWhole)
If Not cell_ori Is Nothing Then
cell_des.Offset(0, 2) = cell_des.Offset(0, 2) + cell_ori.Offset(0, 1)
End If
Next i
Workbooks(nom(dossier)).Close
Next dossier
End With
End Sub |
Partager