Ozgrid Excel Help & Best Practices Forums

Excel Training / Excel Dashboards Reports

# Thread: Number of dimensions of an array

1. I agreed to these rules
Join Date
30th July 2004
Posts
2

## Number of dimensions of an array

How can I check number of dimesions of an array? Thanks.

Excel Video Tutorials / Excel Dashboards Reports

2. Welcome to the OzGrid Forum!

Can you elaborate on your question. Do you mean a worksheet array passed to a VBA routine and you want to know the number of rows and columns in the array? Or you have a variant variable in VBA and you want to know how many entries it contains? Or a dimensioned variable is being passed to another routine and you want to determine how many dimensions it was given? Or ...?

Excel Video Tutorials / Excel Dashboards Reports

3. I agreed to these rules
Join Date
30th July 2004
Posts
2
Originally Posted by Derk
Welcome to the OzGrid Forum!

Can you elaborate on your question. Do you mean a worksheet array passed to a VBA routine and you want to know the number of rows and columns in the array? Or you have a variant variable in VBA and you want to know how many entries it contains? Or a dimensioned variable is being passed to another routine and you want to determine how many dimensions it was given? Or ...?
What I meant is suppose I write a UDF
Function MultiNomial(Probs as variannt) as variant

'Here I check the vaue of probs that user entered. he may enter either
'a "Range" or a "String" or a "Double" or an "Array()". If he enters an
'array it could be either One dimensional or two dimensional.
'How can I check Whether it is one or two dimensional?

Multinomial=...
End function

Excel Video Tutorials / Excel Dashboards Reports

4. M,

If your function comes from a worksheet range it will always be 2 dimensional range.

The followuing code will return 1 for a single dimension array and will return the number of columns in a 2D array.

VB:
```Sub HowBig()
Dim myArray As Variant
'myArray = Array("1", "2", "3", "4")
myArray = Selection.Value
On Error Goto sng
x = UBound(myArray, 2)
MsgBox (x)
Exit Sub
sng:
MsgBox ("1")
End Sub

```
Regards
Weasel

5. Excel Video Tutorials / Excel Dashboards Reports

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
porno