Checking Number of Dimensions In Array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to check the number of dimensions of an already initialized array?
 
Sub test()
Dim i As Long, j As Long
Dim arr(1, 2, 3, 4) As Long

On Error Resume Next
i = 0
Do
j = LBound(arr, i + 1)
If Err.Number Then Exit Do Else i = i + 1
Loop
Err.Clear
On Error GoTo 0

MsgBox i
End Sub



--
Rob van Gelder - http://www.vangelder.co.nz/excel


DigableP said:
Does anyone know how to check the number of dimensions of an already
initialized array?
 
Smaller:

Sub test()
Dim arr(1, 2, 3, 4) As Long
Dim i As Long

On Error Resume Next
Do: i = i - (LBound(arr, i + 1) * 0 = 0): Loop Until Err.Number
On Error GoTo 0

MsgBox i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top