Rokas19990319
New Member
- Joined
- Nov 25, 2022
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Code credit : Fluff
This code takes two workbooks and compares each workbooks Column A's values and if they are different then they are added to the main workbook. The adjustment I need now is that the entire different row would be located to main Workbook, rather than just Column A alone. Any advice or guidance is appreciated.
This code takes two workbooks and compares each workbooks Column A's values and if they are different then they are added to the main workbook. The adjustment I need now is that the entire different row would be located to main Workbook, rather than just Column A alone. Any advice or guidance is appreciated.
VBA Code:
Sub AddMissingItems()
Dim Dic As Object
Dim Arr() As Variant, outArr() As Variant
Dim i As Long, k As Long, iRow As Long
Dim c As Long
Set Dic = CreateObject("Scripting.dictionary")
With Sheets("Sheet1")
c = .Cells(1, Columns.Count).End(xlToLeft).Column
Arr = .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
For i = 1 To UBound(Arr, 1)
If Dic.exists(Arr(i, 1)) = False Then
Dic.Add (Arr(i, 1)), ""
End If
Next
End With
With Workbooks("ExtractFile").Worksheets("Sheet1")
Arr = .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
ReDim outArr(1 To UBound(Arr), 1 To 1)
For i = 1 To UBound(Arr)
If Dic.exists(Arr(i, 1)) = False Then
k = k + 1
outArr(k, 1) = Arr(i, 1)
End If
Next
End With
iRow = Sheets("Sheet1").Range("A" & Rows.Count).End(3).Row + 1
If k <> 0 Then
Sheets("Sheet1").Range("A" & iRow).Resize(k).Value = outArr
k = 0
End If
End Sub