teodormircea
XLDnaute Occasionnel
Bonjour le forum.
je suis en train de m'arracher les cheveux avec une macros qui compare 2 colonnes et sort les valeurs qui n'ont pas de match dans une 3eme
je demande un peux d'aide car je suis débutant et je ne maitrise as très bien VBA
Voici le code
et le fichier de travail,
Merci de votre aide
je suis en train de m'arracher les cheveux avec une macros qui compare 2 colonnes et sort les valeurs qui n'ont pas de match dans une 3eme
je demande un peux d'aide car je suis débutant et je ne maitrise as très bien VBA
Voici le code
Code:
Sub kTest()
Dim a, i As Long, j As Long, w(), b, x, cel
Dim Rng1 As Range, Rng2 As Range, r As Long
Dim b1, f, Y As String
b1 = CLng(InputBox(Prompt:="1ere colonne"))
f = CLng(InputBox(Prompt:="2eme colonne"))
Y = CLng(InputBox(Prompt:="Quelle colonne RESULTAT?"))
Set Rng2 = Range(Cells(1, b1), Cells(Rows.Count, b1).End(xlUp))
Set Rng1 = Range(Cells(1, f), Cells(Rows.Count, f).End(xlUp))
a = Rng1.Value
b = Rng2.Value
r = Application.Max(UBound(a, 1), UBound(b, 1))
ReDim w(1 To r, 1 To 1)
For i = 1 To UBound(a, 1)
If Not IsEmpty(a(i, 1)) Then x = Application.Match(a(i, 1), b, 0)
If IsError(x) Then j = j + 1: w(j, 1) = a(i, 1)
Next
If j > 0 Then Cells(1, Y).Resize(j).Value = w
For i = 5 To j + 4
For Each cel In Rng1
If cel = Range(Y & i) Then
Cells(i, Y - 1) = cel.Offset(, -1)
Exit For ' stop iteration when found matching value
End If
Next cel
Next i
Set Rng1 = Nothing 'clear memory
Set Rng2 = Nothing
End Sub
Merci de votre aide