Announcement

Collapse
No announcement yet.

Number of dimensions of an array

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Number of dimensions of an array

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

  • #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 ...?
    Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

    Comment


    • #3
      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

      Mahindajayadev

      Comment


      • #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.

        Code:
        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
        Kind Regards
        Pesky Weasel
        "I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
        Eagles may soar, but Weasels don't get sucked into jet engines.
        Templates and Calculators
        The Way of the Weasel
        Download Ivan & Colo's HTML Maker Here
        101 Excel Hacks - Great New Book
        Huge Savings on Excel Training

        Comment


        • #5
          Read this article
          http://support.microsoft.com/?kbid=213273
          If you walked away smiling-then for you the price was right

          Comment

          Working...
          X