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
| Option Compare Text
Option Explicit
Sub Compare()
Dim f1 As Worksheet, f2 As Worksheet
Dim Derlig_f1 As Long, Derlig_f2 As Long, i As Long, New_Lig As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set f1 = Sheets("intesta")
Set f2 = Sheets("pippo")
Derlig_f1 = f1.[A100000].End(xlUp).Row
Derlig_f2 = f2.[A100000].End(xlUp).Row
f1.Range(Cells(16, "E"), Cells(Derlig_f1, "H")).FormulaR1C1 = "=IF(RC1<>"""",RC[-4]=RC[4],"""")"
f2.Cells.ClearContents
New_Lig = 1
For i = 16 To Derlig_f1
If f1.Cells(i, "A") = "" Or f1.Cells(i, "B") = "" Or f1.Cells(i, "C") = "" Or f1.Cells(i, "D") = "" Then Exit Sub
If f1.Cells(i, "A") <> f1.Cells(i, "I") Or f1.Cells(i, "B") <> f1.Cells(i, "J") Or f1.Cells(i, "C") <> f1.Cells(i, "K") Or f1.Cells(i, "D") <> f1.Cells(i, "L") Then
f1.Range(Cells(i, "A"), Cells(i, "D")).Copy Destination:=f2.Cells(New_Lig, "A")
New_Lig = New_Lig + 1
f1.Range(Cells(i, "A"), Cells(i, "D")).Delete Shift:=xlUp
'Réécriture des formules
f1.Range(Cells(16, "E"), Cells(Derlig_f1, "H")).FormulaR1C1 = "=IF(RC1<>"""",RC[-4]=RC[4],"""")"
i = i - 1
End If
Next i
Set f1 = Nothing
Set f2 = Nothing
End Sub |
Partager