I am writing a script that will loop through an Excel spreadsheet and find if there are duplicates of selected cells. If there are duplicates then the function will return
Your function is failing because if there is no error raised by UBound()
(i.e. the array is dimensioned) then Err.Number
is 0 and:
Case 0
IsArrayEmpty = True
is executed returning an incorrect result.
The simplest way is to just trap the error:
Function IsArrayEmpty(anArray As Variant) As Boolean
On Error GoTo IS_EMPTY
If (UBound(anArray) >= 0) Then Exit Function
IS_EMPTY:
IsArrayEmpty = True
End Function