VBA IsArray Function

VBA IsArray Function

Objective of VBA IsArray Function

VBA IsArray function is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. This function checks a specified variable or expression is an array or not. It has one input parameter. It returns a Boolean value (True or False). If specified variant is an array then it returns True, Otherwise it returns False. We can’t use this function as a worksheet function. We can only used as a VBA function. This function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA IsArray function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the IsArray function, where we can use this VBA IsArray function and real-time examples.

Syntax of VBA IsArray Function

The syntax of the VBA IsArray function is

IsArray(VarName)

The VBA IsArray function returns a boolean value either True or False.

Parameters or Arguments

The IsArray function has one input parameter or argument.
Where
VarName: It is a required parameter. The VarName that you want to evaluate.

Where we can apply or use VBA IsArray Function?

We can use this VBA IsArray function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Check an expression(“VBAF1”) is an array or not

Here is a simple example of the VBA IsArray function. This below example checks the specified string(VBAF1) is an array or not. The output of below macro is FALSE.

'Check an expression("VBAF1") is an array or not
Sub VBA_IsArray_Function_Ex1()
    
    'Variable declaration
    Dim iExpression As String
    Dim sOutput As Boolean
    
    iExpression = "VBAF1"
    
    sOutput = IsArray(iExpression)
   
    'Display output message
    MsgBox "The expression('VBAF1') is an array or not : " & sOutput, vbInformation, "VBA IsArray Function"
    
End Sub

Output: Here is the screen shot of the first example output.
VBA IsArray Function

Example 2: Check an expression(12345) is an array or not

Here is another example of the VBA IsArray function. This below example checks the specified number(12345) is an array or not. The output of below macro is FALSE.

'Check an expression(12345) is an array or not
Sub VBA_IsArray_Function_Ex2()
    
     'Variable declaration
    Dim iExpression As Integer
    Dim sOutput As Boolean
    
    iExpression = 12345
    
    sOutput = IsArray(iExpression)
   
    'Display output message
    MsgBox "The expression(12345) is an array or not : " & sOutput, vbInformation, "VBA IsArray Function"
    
End Sub

Output: Here is the screen shot of the second example output.
VBA IsArray Function

Example 3: Check an expression(aCnt()) is an array or not

Here is a simple example of the VBA IsArray function. This below example checks the specified variable(aCnt()) is an array or not. The output of below macro returns TRUE.

'Check an expression(aCnt()) is an array or not
Sub VBA_IsArray_Function_Ex3()
    
   'Variable declaration
    Dim aCnt() As Variant
    Dim sOutput As Boolean
          
    sOutput = IsArray(aCnt)
   
    'Display output message
    MsgBox "The expression(aCnt()) is an array or not : " & sOutput, vbInformation, "VBA IsArray Function"
    
End Sub

Output:Here is the screen shot of the third example output.
VBA IsArray Function

Example 4: Check an expression(acnt(5)) is an array or not

Here is a simple example of the VBA IsArray function. This below example checks the specified variable(aCnt(5)) is date or not. The output of below macro is TRUE.

'Check an expression(acnt(5)) is an array or not
Sub VBA_IsArray_Function_Ex4()
    
    'Variable declaration
    Dim aCnt As Variant
    Dim sOutput As Boolean
    
    aCnt = Array(1, 2, 3, 4, 5)
          
    sOutput = IsArray(aCnt)
   
    'Display output message
    MsgBox "The expression(aCnt(5)) is an array or not : " & sOutput, vbInformation, "VBA IsArray Function"
    
End Sub

Output: Here is the screen shot of the fourth example output.
VBA IsArray Function

Instructions to use Macro Codes

Here are the step by step instructions to use the VBA IsArray function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.

List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *