Element in 2D array

mandukes

Forum Rules
Joined
May 25, 2013
Messages
90
Hi

I need to get the elements of 2D array

Code:
Sub ttt()
Dim a(2, 6) As Integer
a(1, 1) = 10
a(1, 2) = 20
a(1, 3) = 30
a(1, 4) = 40
a(1, 5) = 50
a(1, 6) = 60


a(2, 1) = 10
a(2, 2) = 20
a(2, 3) = 30
a(2, 4) = 40


x = UBound(a, 1) - LBound(a, 1)
y = UBound(a, 2) - LBound(a, 2)


MsgBox y & " :  " & x   ' // With this I'm getting 6 : 2


End Sub

I'm looking for an output :

x1 = 6
x2 = 4

Regards
~M
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Why do you expect 6 and 4?
 
Upvote 0
What do you mean by the length? Unless you added an Option Base 1 statement, your array has 3 'rows' and 7 'columns'. What does the number 4 have to do with looping through either of those?
 
Upvote 0
What do you mean by the length? Unless you added an Option Base 1 statement, your array has 3 'rows' and 7 'columns'. What does the number 4 have to do with looping through either of those?

I posted just an example :

Row 1 has 6 elements
Row 2 has 4 elements

So, I was looking for a method to get the same.
 
Upvote 0
Row 2 actually has 6 elements - the 2 you didn’t assign have the default integer value (0). You have to loop through all of them, or use an array of arrays instead of a 2D array.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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