I have two (non empty) arrays (of variants) with numbers. I would like to list all the data that is in the first array and is not in the second array.
Dim existingWorkerIDs() As Variant
Dim newWorkerIDs() As Variant
For Each temp In newWorkerIDs
If existingWorkerIDs.contains(temp) Then
...do sth...
End If
Next temp
Is it possible?
Easily doable by abusing
MATCH.The first procedure is just a test for verification, and also an example of how things have to be declared (and conversely, what declarations you would have to change if you need other variable types, etc).
Which, for the test examples, gives you the expected:
Alternatively, you can change this into a
Functionand have it return the array of unique values.Change this:
Sub listUniqueArrayContents(arr() As Variant, arrCompare() As Variant)to this:
Function listUniqueArrayContents(arr() As Variant, arrCompare() As Variant) As Variantand replace the last-most
For-loop withlistUniqueArrayContents = uniqueValues()