To Determine the 2D array
On 26 Ago, 06:29, Danny wrote:
known that we can use Ubound to determine the array size. However, if
the array is Array(2,5), Ubound just able to determine the "2". May I
know how to find out the "5"?
Hi Danny,
Try this UDF:
'in standard module
'-------------------
Option Explicit
Public Function ABound(ByVal Arr As Variant) As Long
' by Scossa
'return the dimension of an array
' v(9) - 1
' v(9,3) - 2
' v(9,4,5) - 3
Dim i As Long, j As Long
i = 0
j = 0
On Error Resume Next
While Err.number = 0
j = i
i = i + 1
j = UBound(Arr, i)
Wend
On Error GoTo 0
ABound = j
End Function
'code to test ABound() udf:
Sub m()
Dim a(3, 5) As Variant
Dim k As Integer
Dim j As Integer
k = ABound(a)
For j = 1 To k
Debug.Print UBound(a(), j)
Next
End Sub
Tnks for your feedback.
Bye!
Scossa
|