The IsArray Function

Using the IsArray function, you can test whether a variable is an array. The IsArray function returns either true, if the variable is an array, or false, if it's not an array. Here's an example:

1. Insert a new module into the current project and rename it IsArray_Function.

2. Enter the code of the IsThisArray procedure, as shown below:

Sub IsThisArray()

'declare a dynamic array Dim sheetNames() As String Dim totalSheets As Integer Dim counter As Integer

'count the sheets in the current workbook totalSheets = ActiveWorkbook.Sheets.Count 'specify the size of the array ReDim sheetNames(1 To totalSheets) 'enter and show the names of sheets For counter = 1 to totalSheets sheetNames(counter) = ActiveWorkbook.Sheets(counter).Name MsgBox sheetNames(counter) Next counter

'check if this is indeed an array If IsArray(sheetNames) Then

MsgBox "The sheetNames is an array." End If End Sub

0 0

Post a comment