Help with multi dim arrays

J

JLR-Mart

I want to create a multi dim array that is x columns by y rows. y will be
dependent on the number of rows in a spread sheet where a cell value equals a
predefined value and x is fixed at 4. Therefore my array will be 4 columns by
x rows.

Firstly how do I define (and redifne) this array and secondly, when I am
trying to retrive the data from the array how do I know how many rows it has,
is the where the ubound value is used??

Any help greatly appreciated
 
S

Stefi

Sub test()
Dim testarr()
NoOfRows = 10 'example:put here real range ref.
ReDim testarr(4, NoOfRows)
MsgBox UBound(testarr, 2)
End Sub

Regards,
Stefi

„JLR-Mart†ezt írta:
 
J

JLR-Mart

Thanks, that worked in terms of defining the array however, I am defining the
array to be the maximum size it could be, let's say 48 rows. However only 3
rows may get populated within the array but Ubound always reports 48. Can I
find out how many fields in the array are ACTUALLY populated with data in any
way?
 
S

Stefi

Try this:
Sub test()
Dim testarr()
NoOfRows = 10 'example:put here real range ref.
ReDim testarr(4, NoOfRows)
testarr(0, 0) = "szöveg"
testarr(0, 1) = "szöveg"
' MsgBox UBound(testarr, 2)
MsgBox usedrows(testarr)
End Sub
Function usedrows(pararray)
For c = 0 To UBound(pararray, 2)
If IsEmpty(pararray(0, c)) Then Exit For
Next c
usedrows = c
End Function


Regards,
Stefi

„JLR-Mart†ezt írta:
 

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

Top