Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guys,
I use this code to find the difference and create a new array to list in column P. It's stuck. Please help.
I use this code to find the difference and create a new array to list in column P. It's stuck. Please help.
VBA Code:
Sub test7()
Dim ws As Worksheet
Set ws = Worksheets("Data")
Dim v1 As Variant, v2 As Variant, v3 As Variant
Dim coll As Collection
Dim i As Long
'Assumes 0-based Variants
v1 = ws.Range("N1", ws.Range("N1").End(xlDown))
v2 = ws.Range("O1", ws.Range("O1").End(xlDown))
ReDim v3(LBound(v1) To Abs(UBound(v2) - UBound(v1)) - 1)
Set coll = New Collection
For i = LBound(v1) To UBound(v1)
coll.Add v1(i), v1(i)
Next i
For i = LBound(v2) To UBound(v2)
On Error Resume Next
coll.Add v2(i), v2(i)
If Err.Number <> 0 Then
coll.Remove v2(i)
End If
On Error GoTo 0
Next i
For i = LBound(v3) To UBound(v3)
v3(i) = coll(i + 1) 'Collections are 1-based
Debug.Print v3(i)
Next i
End Sub
TestDropDownList_2.xlsm | |||||
---|---|---|---|---|---|
N | O | P | |||
1 | Agent | From ColumnA | Find Missing bet N & O | ||
2 | Cat G | Cat G | |||
3 | Jack S | Ken C | |||
4 | John G | Larry Q | |||
5 | Ken C | Mandy H | |||
6 | Larry Q | Mary K | |||
7 | Mandy H | Nancy L | |||
8 | Mary K | Peter B | |||
9 | Nacy L | Robert M | |||
10 | Peter B | Viola C | |||
11 | Robert M | Warus O | |||
12 | Viola C | Zita V | |||
13 | Warus O | ||||
14 | Zita V | ||||
Data |