Isarray function is to check whether a variable is an array form or not and the return is Boolean which is True or False.
Syntax : IsArray(Variables), Return : True/False
1) Below example is declare as variant but we assigned as array. The return is true.
VBA Vode:
Option Explicit
Sub ExamplesIsArray()
Dim StrVar As Variant
Dim i As Integer
StrVar = Array(1, 2, 3)
If IsArray(StrVar) Then 'The answer is True
For i = LBound(StrVar) To UBound(StrVar)
Debug.Print StrVar(i) ' The answer 1,2,3
Next
Else
Debug.Print "This variables is not an array"
End If
End Sub
Sub ExamplesIsArray()
Dim StrVar As Variant
Dim i As Integer
StrVar = Array(1, 2, 3)
If IsArray(StrVar) Then 'The answer is True
For i = LBound(StrVar) To UBound(StrVar)
Debug.Print StrVar(i) ' The answer 1,2,3
Next
Else
Debug.Print "This variables is not an array"
End If
End Sub
Note: When the return is true we can loop thru this array from lower to upper bound.
2) Below example originally declare as array even we don't assigned any array the result still True.
VBA Vode:
Option Explicit
Sub Examples_IsArray()
Dim MyArray() As String
If IsArray(MyArray) Then
Debug.Print True 'The answer is True
Else
Debug.Print False
End If
End Sub
Sub Examples_IsArray()
Dim MyArray() As String
If IsArray(MyArray) Then
Debug.Print True 'The answer is True
Else
Debug.Print False
End If
End Sub
Note: For the above example we have to use redim statement to assigned array.
Other Reference-Isarray-function.htm
Practice makes perfect. Thank You.
macro enabled excel
excel macro
vba coding
vba code
No comments:
Post a Comment