Option Explicit
Sub Stock()
Application.ScreenUpdating = False
' Clear nous permett de supprimerles précédentes recherches
Sheets(3).Range("A1").CurrentRegion.Offset(1, 0).Clear
Dim NbCols As Integer, firstAddress As Variant, _
ReferenceNewArticle As Range, ReferenceOldArticle As Range, _
Derligne As Long, X As Variant, c As Variant, _
FirstEmptyLineSheet3 As Integer, FirstContentLineSheet1 As Integer, i As Integer, ContentLineSheet2 As Integer
Set ReferenceNewArticle = Sheets(2).Range("A1:" & Sheets(2).Range("A65536").End(xlUp).Address)
Set ReferenceOldArticle = Sheets(1).Range("A1:" & Sheets(1).Range("A65536").End(xlUp).Address)
NbCols = Sheets(2).Range("A1:F1").Column
'Alternative pour : NbCols = Sheets(2).Range("IV5").End(xlToLeft).Column
Derligne = Sheets(1).Range("A65536").End(xlUp).Row
'Premiere Boucle On cherche si les articles dans referenceNewArticle existent dans ReferenceOldArticle
'si il ne trouve pas la ref dans nouveau c est un nouvel article
For Each X In ReferenceNewArticle
i = i + 1
'With nous permet de .range au lieu de Sheets(1).range( dans notre boucle
With ReferenceOldArticle
Set c = .Find(X.Value)
'ici on teste les modifications nouveau produit (X) dans ancien (c)
If Not c Is Nothing Then 'On a trouvé
firstAddress = c.Address
Debug.Print "c : " & c.Row
Debug.Print "X : " & X.Row
Debug.Print NbCols
'Do
'OK le probleme est que value est pour une cellule Taper une boucle for sur chaque cellule avant de férifier
Cells(8, 1)
.Range("A" & Rows.Count).End(xlUp).Row
Cells(Int(Rnd * 10) + 1, 1).Value
'On teste si les données sont identiques
If Sheets(1).Range("A" & c.Row).Value <> Sheets(2).Range("A" & c.Row).Value Then
Debug.Print (c.Row)
End If
'On copie le résultat
'Alternative pour copier une ligne
'Worksheets("Feuille2").Range("A1").value = Worksheets("Feuille1").Range("A1").Value
'ThisWorkbook.Worksheets("Ajout").Range("A" & FirstEmptyLineSheet3 & ":F" & FirstEmptyLineSheet3).Value = _
'ThisWorkbook.Worksheets("Nouveau").Range("A" & i & ":F" & i).Value
Set c = .FindNext(c) 'On continue à chercher ...
'Loop While Not c Is Nothing And c.Address <> firstAddress 'Les condiftions du Do (cf. plus haut)
Else 'la reference est nouvelle
Debug.Print ("ELSE")
Debug.Print "X : " & X.Row
'numéro de ligne en feuille 1
ContentLineSheet2 = i
'On repère la première ligne Vide en feuille 3
FirstEmptyLineSheet3 = IIf(ThisWorkbook.Worksheets("Ajout").Range("A1").Value = _
"", 1, ThisWorkbook.Worksheets("Ajout").Range("A65536").End(xlUp).Row + 1)
'On copie le résultat
ThisWorkbook.Worksheets("Ajout").Range("A" & FirstEmptyLineSheet3 & ":F" & FirstEmptyLineSheet3).Value = _
ThisWorkbook.Worksheets("Nouveau").Range("A" & i & ":F" & i).Value
i = i + 1
End If
End With
Next
'Worksheets("Sheet1").Activate
'ActiveCell.CurrentRegion.Select
Sheets(3).Select 'On affiche le resultat
Application.ScreenUpdating = True
End Sub