Comparaison deux feuilles et affichage lignes qui diffèrent (resultats)
Invité
Bonjour,
J'avais un code qui permettait de faire une recherche valeur. Je vous l'affiche ci-après (et donne le fichier aussi enfin un fichier exemple ) mais je voudrais un programme VBA qui compare deux fichiers et qui affiche justement dans une autre feuille du classeur "resultat" , les lignes qui diffèrent entre les deux fichiers.
Function FindAll(ByVal sText As String, ByRef oSht As Worksheet, ByRef sRange As String, ByRef arMatches() As String) As Boolean
' --------------------------------------------------------------------------------------------------------------
' FindAll - To find all instances of the1 given string and return the row numbers.
' If there are not any matches the function will return false
' --------------------------------------------------------------------------------------------------------------
On Error GoTo Err_Trap
Dim rFnd As Range ' Range Object
Dim iArr As Integer ' Counter for Array
Dim rFirstAddress ' Address of the First Find
' -----------------
' Clear the Array
' -----------------
Erase arMatches
With oSht.Range(sRange)
.Interior.Pattern = xlNone 'reset range's interior color
Set rFnd = .Find(what:=sText, LookIn:=xlValues, lookAt:=xlPart)
If Not rFnd Is Nothing Then
rFirstAddress = rFnd.Address
Do Until rFnd Is Nothing
iArr = iArr + 1
rFnd.Interior.Color = vbRed 'set interior color to red for found string
ReDim Preserve arMatches(iArr)
arMatches(iArr) = rFnd.Row 'rFnd.Address pour adresse complete ' rFnd.Row Pour N° de ligne
Set rFnd = oSht.Range(sRange).FindNext(rFnd)
If rFnd.Address = rFirstAddress Then Exit Do ' Do not allow wrapped search
Loop
FindAll = True
Else
' ----------------------
' No Value is Found
' ----------------------
FindAll = False
End If
' -----------------------
' Error Handling
' -----------------------
End With
Err_Trap:
If Err <> 0 Then
MsgBox Err.Number & " " & Err.Description, vbInformation, "Find All"
Err.Clear
FindAll = False
Exit Function
End If
End Function
Sub test()
Dim liste() As String, plage As String, a
Dim test As Boolean
Dim ws As Worksheet
Sheets("resultats").Cells.Clear
Set ws = Sheets("TiersM-1")
plage = "A2:G200"
'on recherche avril dans feuil1 et feuil2
test = FindAll("SG", ws, plage, liste())
'si avril trouve sur feui1 mettre les numéros de ligne en colonne A sur feuille resultats
If test Then Sheets("resultats").Cells(2, 1).Resize(UBound(liste) + IIf(LBound(liste) = 0, 1, 0), 1) = Application.Transpose(liste)
Set ws = Sheets("TiersM")
test = FindAll("SG", ws, plage, liste())
'si avril trouve sur feui2 mettre les numéros de ligne en colonne B sur feuille resultats
If test Then Sheets("resultats").Cells(2, 2).Resize(UBound(liste) + IIf(LBound(liste) = 0, 1, 0), 1) = Application.Transpose(liste)
End SubMerci beaucoup.