ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamic multidimensional arrays (https://www.excelbanter.com/excel-programming/363606-re-dynamic-multidimensional-arrays.html)

Jim Thomlinson

Dynamic multidimensional arrays
 
Give this a whirl... The perserve key word keeps the values that may already
be in the array. Without it any values in the array would be lost. Not
neseccary in this case...

Sub test()
Dim ary() As Integer

ReDim Preserve ary(10, 10)

ary(0, 0) = 1
ary(0, 1) = 2

End Sub

Note that you can still resize the array at any time but you can only resize
the last dimension...

--
HTH...

Jim Thomlinson


"ispy99" wrote:

All,

I am trying to write some VBA code for an excel application. I need to read
in a CSV file with a set number of fields but variable number of rows. I
have been able to open the file and read the contents, however I am having a
problem loading the data into an array. I believe I am simply not
understanding how to work with multidimensional dynamic arrays. In this case
I have two fields with a variable number of rows. I know in other languages
like Java I would instantiate a Vector (for example) and then add as many
elements as I needed. VBA seems to require knowing the size of the array
when it is created with Dim. Any suggestions?



All times are GMT +1. The time now is 05:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com