# Compare Two Arrays

For one of my projects I needed a function to compare two arrays. The following function returns true if both array have the same elements (regardless of their position in arrays).

```
Function ArraysAreEqual (vA As Variant, vB As Variant) As Variant
Dim IsEqual As Variant
ArraysAreEqual = True
Forall a In vA
IsEqual = False
Forall b In vB
If a = b Then
IsEqual = True
Exit Forall
End If
End Forall
If Not IsEqual Then
ArraysAreEqual = False
Exit Function
End If
End Forall
Forall b In vB
IsEqual = False
Forall a In vA
If b = a Then
IsEqual = True
Exit Forall
End If
End Forall
If Not IsEqual Then
ArraysAreEqual = False
Exit Function
End If
End Forall
End Function
```

To execute your code only when both array are different simply use

```
If Not (ArraysAreEqual ( mBefore, mAfter )) Then
' your code goes here
' ...
End If
```