Problems Converting 1-D Array to 2-D Array

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

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)
 
You can only redim the outer/last dimension of an array when you use
preserve. This is explained in the help on dynamic arrays.
 

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

Similar Threads


Back
Top