View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Dealing with unknown array sizes

Hi robert,

You can only redim preserve the last dimension of an array. It is very
confusing from the programming point of view but you need to put the known
fixed number of columns in the first dimension and the unknown number of rows
in the 2nd dimension and redim preserve each time you want to add a row. The
following code for the redim preserve.

ReDim Preserve myArr(1 To 5, 1 To UBound(myArr, 2) + 1)

Have fun. It will test you logic turning the data around.

--
Regards,

OssieMac


"Robert Crandal" wrote:

I have a multi-dimensional array which is initially defined
as follows:

Dim MyArr() as String

My VBA code will then search all rows that contain data.
(BTW, each row contains 5 columns of data.)

If a row of data is found that matches the search criteria,
I want to place all that string data into the "MyArr" array.
So, if my search yields 230 rows of string data, I want my final
array size to be EXACTLY 230 rows by 5 columns, or:

ReDim MyArr (1 to 230, 1 to 5)

Can I redimension the array each time a search hit is
found and continuously add data to this array?? I guess I'm
really looking for a string array that grows each time a search
hit is found.

I know I could create an oversized array to begin with, but
in my case it is important that my array size be EXACTLY
the same number as the total number of rows that I will place
in the array. Anybody know what I can do???

Thank you!


.