Sub Macro1()
'
' Macro1 Macro
'
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'
Application.Dialogs.Item(xlDialogOpen).Show
Range("A1:AH" & Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
ActiveWindow.Close
Windows("Cotisations macro.xlsm").Activate
Range("A1").Select
ActiveSheet.Paste
Range("AI1").Select
ActiveCell.FormulaR1C1 = "Doublons"
'Recherche de doublon dans les contrats
Range("AI2").Select
ActiveCell.FormulaR1C1 = _
"=IF(COUNTIF(R2C15:RC[-20],RC[-20])=1,SUMIF(C[-20],RC[-20],C[-4]),"""")"
'Tirer la formule vers le bas
Dim LastRw As Long
LastRw = Sheets("Feuil1").Cells(Rows.Count, 1).End(xlUp).Row
Range("AI2:AI" & LastRw).FillDown
'Analyse les doublons
Range("AJ1").Select
ActiveCell.FormulaR1C1 = "Analyse doublons"
Range("AJ2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=1,""Pas de doublon"",""Doublon"")"
Range("AJ2").Select
'Tirer la formule vers le bas
LastRw = Sheets("Feuil1").Cells(Rows.Count, 1).End(xlUp).Row
Range("AJ2:AJ" & LastRw).FillDown
'Masque la cellule
Columns("AI:AI").Select
Selection.EntireColumn.Hidden = True
'Recherche des tarifs chelou
Range("AK1").Select
ActiveCell.FormulaR1C1 = "Analyse tarif"
Range("AK2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-17],Tarif!R1C1:R152C2,2,FALSE),""Tarif à contrôler"")"
'Tirer la formule vers le bas
LastRw = Sheets("Feuil1").Cells(Rows.Count, 1).End(xlUp).Row
Range("AK2:AK" & LastRw).FillDown
'Colonne pour resumer les contrôles
Range("AL1").Select
ActiveCell.FormulaR1C1 = "Contrôles"
Range("AL2").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(RC[-2]=""Doublon"",RC[-1]=""Tarif à contrôler""),""Contrôle à faire"",""Pas de contrôle"")"
'Tirer la formule vers le bas
LastRw = Sheets("Feuil1").Cells(Rows.Count, 1).End(xlUp).Row
Range("AL2:AL" & LastRw).FillDown
'copier coller valeurs pour enlever les formules
Columns("AJ:AL").Select
Range("AL1").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub