Complement of Two Arrays

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi,
try the macro in an empty WorkSheet:
Code:
Sub Complement()
Dim tbl(), tbl1, tbl2, i&, x&

tbl1 = Array("123-1", "345-6", "678-9")
tbl2 = Array("123-1", "345-6", "998-7")

For i = LBound(tbl2) To UBound(tbl2)
  If IsError(Application.Match(tbl2(i), tbl1, 0)) Then
    x = x + 1
    ReDim Preserve tbl(1 To x)
    tbl(x) = tbl2(i)
  End If
Next i

Cells(1, 1).Resize(UBound(tbl)) = Application.Transpose(tbl)
End Sub
Best regards.
 
Upvote 0
Also, I'd just like to know what "i&" and "x&" mean.....
(Its the first time I'm seeing such kind of declaration)
 
Upvote 0
This shortly declaration is the same than the declaration x As Long. Supposeddly, my shorty declaration is a little obsolete, but I use this declaration (only for Long variables), because I like this type declaration and I use most often this type of declaration. Best regards.
 
Last edited:
Upvote 0
Alright! I got to know something new today! :)
Thanks once again...Your code was of real great help!
 
Upvote 0

Forum statistics

Threads
1,215,415
Messages
6,124,764
Members
449,187
Latest member
hermansoa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top