ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems Converting 1-D Array to 2-D Array (https://www.excelbanter.com/excel-programming/326257-problems-converting-1-d-array-2-d-array.html)

ExcelMonkey[_190_]

Problems Converting 1-D Array to 2-D Array
 
I had d 1-D array which I was loading with cell addresses
within a For Loop. I was redimensionin the array based
on a counter witin my loop since I don't know how big to
make it. It was working fine. Then I decided to
introduce a second dimension. All I wanted to do was
introduce a new column in the array which I was not yet
filling. That is, I still want to my data to go into
column 0. I can't seem to load the array with data. I
have skipped out how I progress though the cells as this
is extensive code. But I have included the main lines.
I have done something wrong in the new version. Can
anyone tell me what I have done wrong? Thanks


Old:
UniqueCount = 0
ReDim UniqueCellAddressArray(0 To 0)
For X = 1 to 100
UniqueCount = UniqueCount + 1
ReDim Preserve UniqueCellAddressArray(0 To UniqueCount)
UniqueCellAddressArray(UniqueCount, 0) =
CurrentCell1.Parent.Name & "!" & CurrentCell1.Address
Debug.Print UniqueCellAddressArray(UniqueCount)
Next

New:
UniqueCount = 0
ReDim UniqueCellAddressArray(0 To 0, 0 To 0)
UniqueCount = UniqueCount + 1
ReDim Preserve UniqueCellAddressArray(0 To UniqueCount, 0
To 1)
UniqueCellAddressArray(UniqueCount, 0) =
CurrentCell1.Parent.Name & "!" & CurrentCell1.Address
Debug.Print UniqueCellAddressArray(UniqueCount, 0)

Tom Ogilvy

Problems Converting 1-D Array to 2-D Array
 
You can only redim the outer/last dimension of an array when you use
preserve. This is explained in the help on dynamic arrays.

--
Regards,
Tom Ogilvy

"ExcelMonkey" wrote in message
...
I had d 1-D array which I was loading with cell addresses
within a For Loop. I was redimensionin the array based
on a counter witin my loop since I don't know how big to
make it. It was working fine. Then I decided to
introduce a second dimension. All I wanted to do was
introduce a new column in the array which I was not yet
filling. That is, I still want to my data to go into
column 0. I can't seem to load the array with data. I
have skipped out how I progress though the cells as this
is extensive code. But I have included the main lines.
I have done something wrong in the new version. Can
anyone tell me what I have done wrong? Thanks


Old:
UniqueCount = 0
ReDim UniqueCellAddressArray(0 To 0)
For X = 1 to 100
UniqueCount = UniqueCount + 1
ReDim Preserve UniqueCellAddressArray(0 To UniqueCount)
UniqueCellAddressArray(UniqueCount, 0) =
CurrentCell1.Parent.Name & "!" & CurrentCell1.Address
Debug.Print UniqueCellAddressArray(UniqueCount)
Next

New:
UniqueCount = 0
ReDim UniqueCellAddressArray(0 To 0, 0 To 0)
UniqueCount = UniqueCount + 1
ReDim Preserve UniqueCellAddressArray(0 To UniqueCount, 0
To 1)
UniqueCellAddressArray(UniqueCount, 0) =
CurrentCell1.Parent.Name & "!" & CurrentCell1.Address
Debug.Print UniqueCellAddressArray(UniqueCount, 0)





All times are GMT +1. The time now is 08:01 PM.

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