Function to return Number of Dimensions to an Array?

HedgePig

Board Regular
Joined
Jun 27, 2002
Messages
146
I thought Excel VBA had a built in function which returned the number of dimensions to an array - but I can't find it in the online help. Is there such a function?

HedgePig

P.S. I wrote a little function myself but I really want to find the name of that built-in function!

Sub TestDimensionsCount()
Dim testarray(1, 2, 3)
MsgBox NumDims(testarray)
End Sub

'Returns the number of dimensions of the array parameter
Function NumDims(a As Variant) As Integer

If Not IsArray(a) Then
NumDims = 0
Exit Function
End If

NumDims = 1
On Error GoTo NoMoreDimsErr
Do
ub = UBound(a, NumDims)
NumDims = NumDims + 1
Loop

NoMoreDimsErr:
NumDims = NumDims - 1
On Error GoTo 0
End Function
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Juan

Thanks for the reply, Juan. I would have sworn that I'd used that missing built-in function before. Maybe I ended up writing same little function myself and had forgotten about it! Anyhow thanks for confirming that I'm suffering from a memory leak and that there is indeed no such function

Yours forgetfully
HedgePig
 
Upvote 0
There isn't a native VB function per se, but a udf will work, see my link. :wink:
 
Upvote 0
Thanks for your reply, Nate

Actually I had come across your post when searching the board but was convinced that there was an internal function. By the way, what's a udf?

Yours in a random dimension
HedgePig
 
Upvote 0
Nope, there is no native functionality of this nature to be found. This api trickery should be pretty quick-like though.

UDF = User Defined Function.

Bon chance. :)
 
Upvote 0

Forum statistics

Threads
1,221,537
Messages
6,160,401
Members
451,645
Latest member
hglymph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top