Bonjour je cherche à comparer deux listes en A et C d'une feuille exel de 200000 lignes avec si valeur de C est dans A alors copier valeur écrite en B dans D avec mais sans application transpose qui limite le résultat à 65000. Merci d'avance
Sub report()
acopier = "nok"
tablo = Range("A2:D" & Range("A" & Rows.Count).End(xlUp).Row)
For m = LBound(tablo, 1) To Range("C" & Rows.Count).End(xlUp).Row - 1
For p = LBound(tablo, 1) To UBound(tablo, 1)
If tablo(m, 3) = tablo(p, 1) Then
acopier = tablo(p, 2)
End If
Next
tablo(m, 4) = acopier
acopier = "nok"
Next
Range("A2").Resize(UBound(tablo, 1), UBound(tablo, 2)) = tablo
End Sub
Option Explicit
Sub Si_doublon()
Dim c As Range, cc As Range
Application.ScreenUpdating = 0: Application.EnableEvents = 0
Columns(4).Clear
For Each c In Sheets("Feuil1").Columns(3).SpecialCells(xlCellTypeConstants)
Set cc = Sheets("Feuil1").Columns(1).Find(c.Value, LookIn:=xlValues)
If Not cc Is Nothing Then c.Offset(0, 1) = cc.Offset(0, 1)
Next
Application.ScreenUpdating = -1: Application.EnableEvents = -1
End Sub
Sub es()
Dim t(), m As Object, i As Long
Set m = CreateObject("Scripting.Dictionary")
t = Range("a2:b" & Cells(Rows.Count, 1).End(3).Row)
For i = 1 To UBound(t): m(t(i, 1)) = t(i, 2): Next i
t = Range("c2:d" & Cells(Rows.Count, 3).End(3).Row)
For i = 1 To UBound(t)
If m.Exists(t(i, 1)) Then t(i, 1) = m(t(i, 1)) Else t(i, 1) = t(i, 2)
Next i
[d2].Resize(UBound(t, 1), 1).Value = t
End Sub
Sub est()
Dim t(), m As New Dictionary, i As Long
t = Range("a2:b" & Cells(Rows.Count, 1).End(3).Row)
For i = 1 To UBound(t): m(t(i, 1)) = t(i, 2): Next i
t = Range("c2:d" & Cells(Rows.Count, 3).End(3).Row)
For i = 1 To UBound(t)
If m.Exists(t(i, 1)) Then t(i, 1) = m(t(i, 1)) Else t(i, 1) = t(i, 2)
Next i
[d2].Resize(UBound(t, 1), 1).Value = t
End Sub
Sub tata()
Dim i&, j&, l&, m&, t, d(), e()
Dim ab1 As Range, ab2 As Range, c1 As Range, c2 As Range
With Me
l = .Cells(.Rows.Count, 1).End(xlUp).Row - 1
Set ab1 = .Cells(1, 1).Offset(1).Resize(l, 2).Cells
m = .Cells(.Rows.Count, 3).End(xlUp).Row - 1
Set c1 = .Cells(1, 3).Offset(1).Resize(m, 1).Cells
End With
With Application: .ScreenUpdating = 0: .EnableEvents = 0: .Calculation = -4135: End With
Sheets.Add After:=Sheets(Sheets.Count)
With ActiveSheet
ab1.Copy Destination:=.Range("A2")
Set ab2 = .Cells(2, 1).Resize(l, 2).Cells
With .Sort
.SortFields.Add Key:=ab2.Columns(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange ab2
.Header = xlNo: .MatchCase = False: .Orientation = xlTopToBottom: .SortMethod = xlPinYin
.Apply
.SortFields.Clear
End With
d = ab2.Value
c1.Copy Destination:=.Range("E2")
Set c2 = .Cells(2, 4).Resize(m, 3).Cells
With c2.Cells(1, 1): .FormulaR1C1 = "nok": .AutoFill Destination:=c2.Columns(1), Type:=xlFillValues: End With
With c2.Cells(1, 3): .FormulaR1C1 = "1": .AutoFill Destination:=c2.Columns(3), Type:=xlFillSeries: End With
With .Sort
.SortFields.Add Key:=c2.Columns(2), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange c2
.Header = xlNo: .MatchCase = False: .Orientation = xlTopToBottom: .SortMethod = xlPinYin
.Apply
.SortFields.Clear
End With
e = c2.Value
j = 1
For i = 1 To m
t = e(i, 2)
Do While t > d(j, 1) And j < l: j = j + 1: Loop
If t = d(j, 1) Then e(i, 1) = d(j, 2)
Next
c2.Value = e
With .Sort
.SortFields.Add Key:=c2.Columns(3), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange c2
.Header = xlNo: .MatchCase = False: .Orientation = xlTopToBottom: .SortMethod = xlPinYin: .Apply
End With
c1.Offset(, 1).Value = c2.Value
Application.DisplayAlerts = False: .Delete: Application.DisplayAlerts = True
End With
Me.Activate
With Application: .Calculation = -4105: .EnableEvents = 1: .ScreenUpdating = 1: End With
End Sub
Bonjour ℝOGER2327 et merci d'avoir répondu, votre macro est rapide mais il y a des nok quelquefois sur des comparaisons qui devraient être positive
Do While t > d(j, 1) And j < m: j = j + 1: Loop
Do While t > d(j, 1) And j < l: j = j + 1: Loop
bonjour guytares ,pierrejean,DoubleZero
sur 200000 lignes on pourrait tenter un dico ??
Code:Sub es() Dim t(), m As Object, i As Long Set m = CreateObject("Scripting.Dictionary") t = Range("a2:b" & Cells(Rows.Count, 1).End(3).Row) For i = 1 To UBound(t): m(t(i, 1)) = t(i, 2): Next i t = Range("c2:d" & Cells(Rows.Count, 3).End(3).Row) For i = 1 To UBound(t) If m.Exists(t(i, 1)) Then t(i, 1) = m(t(i, 1)) Else t(i, 1) = t(i, 2) Next i [d2].Resize(UBound(t, 1), 1).Value = t End Sub
ou en activant la ref.. Scripting.Dictionary un peu + rapide
Code:Sub est() Dim t(), m As New Dictionary, i As Long t = Range("a2:b" & Cells(Rows.Count, 1).End(3).Row) For i = 1 To UBound(t): m(t(i, 1)) = t(i, 2): Next i t = Range("c2:d" & Cells(Rows.Count, 3).End(3).Row) For i = 1 To UBound(t) If m.Exists(t(i, 1)) Then t(i, 1) = m(t(i, 1)) Else t(i, 1) = t(i, 2) Next i [d2].Resize(UBound(t, 1), 1).Value = t End Sub
Sub runtime()
On Error Resume Next
ThisWorkbook.VBProject.References.AddFromFile "C:\Windows\System32\scrrun.dll"
ThisWorkbook.VBProject.References.AddFromFile "C:\Windows\SysWOW64\scrrun.dll"
End Sub
Sub est()
Dim t(), m As New Dictionary, i As Long
With Application
.Calculation = xlCalculationManual: .ScreenUpdating = 0: .DisplayAlerts = 0
t = Range("a2:b" & Cells(Rows.Count, 1).End(3).Row)
For i = 1 To UBound(t): m(t(i, 1)) = t(i, 2): Next i
t = Range("c2:d" & Cells(Rows.Count, 3).End(3).Row)
For i = 1 To UBound(t)
If m.Exists(t(i, 1)) Then t(i, 1) = m(t(i, 1)) Else t(i, 1) = t(i, 2)
Next i
[d2].Resize(UBound(t, 1), 1).Value = t
.Calculation = xlCalculationAutomatic: .ScreenUpdating = 1: .DisplayAlerts = 1
End With
End Sub
ROGER2327
Bonjour et merci pour vos solutions, j'ai essayé le code original avec Do While t > d(j, 1) And j < l: j = j + 1: Loop
que vous avez mis en correction mais qui est aussi dans l'original, je vous joint un fichier avec les fausses erreurs en jaune. salutations
If t = d(j, 1) Then e(i, 1) = d(j, 2)
If t = d(j, 1) Then e(i, 1) = d(j, 2): j = j + 1
Sub tata()
Const a$ = "A1", b$ = "C1" 'Début de la plage de données, début de la plage de résultats.
Dim i&, j&, l&, m&, t, d(), e()
Dim a1 As Range, a2 As Range, b1 As Range, b2 As Range
With Me
l = .Cells(.Rows.Count, .Range(a).Column).End(xlUp).Row - .Range(a).Row
m = .Cells(.Rows.Count, .Range(b).Column).End(xlUp).Row - .Range(b).Row
If l = 0 Or m = 0 Then Exit Sub
Set a1 = .Range(a).Offset(1).Resize(l, 2).Cells
Set b1 = .Range(b).Offset(1).Resize(m, 1).Cells
End With
With Application: .ScreenUpdating = 0: .EnableEvents = 0: .Calculation = -4135: End With
Sheets.Add After:=Sheets(Sheets.Count)
With ActiveSheet
a1.Copy Destination:=.Range("A2")
Set a2 = .Cells(2, 1).Resize(l, 2).Cells
With .Sort
.SortFields.Clear
.SortFields.Add Key:=a2.Columns(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange a2
.Header = xlNo: .MatchCase = False: .Orientation = xlTopToBottom: .SortMethod = xlPinYin
.Apply
End With
d = a2.Value
b1.Copy Destination:=.Range("E2")
Set b2 = .Cells(2, 4).Resize(m, 3).Cells
On Error Resume Next
With b2.Cells(1, 1): .FormulaR1C1 = "nok": .AutoFill Destination:=b2.Columns(1), Type:=xlFillValues: End With
With b2.Cells(1, 3): .FormulaR1C1 = "1": .AutoFill Destination:=b2.Columns(3), Type:=xlFillSeries: End With
On Error GoTo 0
With .Sort
.SortFields.Clear
.SortFields.Add Key:=b2.Columns(2), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange b2
.Header = xlNo: .MatchCase = False: .Orientation = xlTopToBottom: .SortMethod = xlPinYin
.Apply
e = b2.Value
j = 1
For i = 1 To m
t = e(i, 2)
Do While t > d(j, 1) And j < l: j = j + 1: Loop
If t = d(j, 1) Then e(i, 1) = d(j, 2): j = j + 1
Next
b2.Value = e
.SortFields.Clear
.SortFields.Add Key:=b2.Columns(3), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange b2
.Header = xlNo: .MatchCase = False: .Orientation = xlTopToBottom: .SortMethod = xlPinYin: .Apply
End With
b1.Offset(, 1).Value = b2.Value
Application.DisplayAlerts = False: .Delete: Application.DisplayAlerts = True
End With
Me.Activate
With Application: .Calculation = -4105: .EnableEvents = 1: .ScreenUpdating = 1: End With
End Sub
If m.Exists(t(i, 1)) Then t(i, 1) = m(t(i, 1)) Else t(i, 1) = "nok"