Sub MiseAJourContrats()
Dim NomFichier As Variant
Dim WbDest As Workbook
Dim shDest As Worksheet
Dim PlageSource As Range, PlageDest As Range, cSource As Range, cDest As Range
Dim Adr1 As String
With Sheets("Table")
Set PlageSource = .Range("C10:C" & .Range("C" & .Rows.Count).End(xlUp).Row)
End With
NomFichier = Application.GetOpenFilename(filefilter:="Classeur Microsoft Excel (*.xls)," & ThisWorkbook.Path & "\" & "*.xls", Title:="Choisir le fichier souhaité")
If NomFichier <> False Then
'Reférencer le classeur
Set WbDest = Workbooks.Open(Filename:=NomFichier)
Else
Exit Sub
End If
'La feuille à renseigner
On Error Resume Next
Set shDest = WbDest.Sheets("cat")
On Error GoTo 0
'Si elle n'existe pas sortir
If shDest Is Nothing Then Exit Sub
'Déterminer la plage des numéro de contrat
With shDest
Set PlageDest = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
End With
For Each cSource In PlageSource.Cells
With PlageDest
Set cDest = .Find(what:=cSource, LookIn:=xlValues, lookat:=xlWhole)
If Not cDest Is Nothing Then
Adr1 = cDest.Address
Do
With cDest
'Si numéro de contrat non à jour
If .Value <> cSource.Offset(, 1) Then
.Value = cSource.Offset(, 1) 'Nouveau Numéro de contrat
With .Offset(, 54)
'Si date non à jour
If .Value <> cSource.Offset(, 54) Then
.Value = cSource.Offset(, 5) 'Date Fin
.NumberFormat = "dd/mm/yyyy"
End If
End With
End With
Set cDest = .FindNext(cDest)
If cDest Is Nothing Then Exit Do
Loop While cDest.Address <> Adr1
End If
End With
Next cSource
End Sub