VBA Function: IsArray
The VBA IsArray function returns True if the variable points to an array or False if it does not.
Usage:
IsArray(variable)
Example of Usage
The following function returns the number of elements in an array or the value -1 if it is not an array (determined using the IsArray function):
Function count(myArray)
If IsArray(myArray) Then
count = UBound(myArray) + 1
Else
count = -1
End If
End Function
Example of values returned by this function:
Sub example()
'Example with an array (with 2 elements)
array1 = Array("EXCEL", "PRATIQUE")
MsgBox count(array1) 'Returns: 2
'Example with an array (with 4 elements)
Dim array2(3)
MsgBox count(array2) 'Returns: 4
'Example with a variable
text1 = "EXCEL"
MsgBox count(text1) 'Returns: -1
End Sub