I am trying to write a VBA code that cross checks all of the values in one array with another (X with Y) and to copy the value into a new array if it is duplicated (FinalResults). So far I have the following code and would greatly appreciate some guidance on how to write it correctly.
Function lnArray(X as Variant, Y as Variant) As Variant
Dim counter1 As Integer
Dim data As Integer
Dim FinalResults() As Variant
For counter1 = 1 To Max
For Each data In X
If data.Value = Y.Value Then
counter1 = counter1 + 1
ReDim Preserve FinalResults(counter1)
FinalResults(counter1) = data.Value
End If
Next data
Next counter1
End Function
Notsomewhere.