Rokas19990319
New Member
- Joined
- Nov 25, 2022
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
@Fluff
Dear Fluff,
You helped someone almost a year ago and provided this code, I was hoping you could slightly adjust this code to take the different values rather than matching ones and paste them into workbook A rather than into a new one. It would be a lifesaver as this code works surprisingly fast and my old code does this same thing for many hours with many rows and is way longer
It would also be great if in the new workbook it would be pasted below the last used row
Dear Fluff,
You helped someone almost a year ago and provided this code, I was hoping you could slightly adjust this code to take the different values rather than matching ones and paste them into workbook A rather than into a new one. It would be a lifesaver as this code works surprisingly fast and my old code does this same thing for many hours with many rows and is way longer
It would also be great if in the new workbook it would be pasted below the last used row
VBA Code:
Sub MY_SUB()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim WbkA As Workbook, WbkB As Workbook, WbkC As Workbook
Dim Ary As Variant, Nary As Variant
Dim Dic As Object
Dim r As Long, c As Long, nr As Long
Set WbkA = Workbooks("Workbook.xlsx")
'Set WbkB = Workbooks("Workbook.xlsx")
Set WbkC = Workbooks("ExtractFile.xlsx")
Set Dic = CreateObject("scripting.dictionary")
Dic.comparemode = 1
With WbkC.Sheets(1)
Ary = .Range("A1", .Range("A" & Rows.Count).End(xlUp)).Value2
End With
For r = 1 To UBound(Ary)
Dic(Ary(r, 1)) = Empty
Next r
With WbkA.Sheets(1)
c = .Cells(1, Columns.Count).End(xlToLeft).Column
Ary = .Range("A1", .Range("A" & Rows.Count).End(xlUp)).Resize(, c).Value2
End With
ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
For r = 1 To UBound(Ary)
If Dic.Exists(Ary(r, 5)) Then
nr = nr + 1
For c = 1 To UBound(Ary, 2)
Nary(nr, c) = Ary(r, c)
Next c
End If
Next r
WbkA.Sheets(1).Range("A35000").Resize(nr, UBound(Nary, 2)).Value = Nary
'WbkA.Close True
'WbkB.Close True
'WbkC.Close True
MsgBox "GENERATED!"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Last edited by a moderator: