Re: Set up array to write to table?



Hi Ed,

Sorry to pop your bubble, although it will save you some work...

You *can* use ReDim Preserve with a multidimensional array. It's just that
you're restricted to changing the number representing the *last* dimension.
For a two-dimensional array MyArray(x,y), you can change y but you can't
change x. In other words, you can make more rows but you can't change the
number of columns in the table. This is explained pretty well by the VBA
help topic on the ReDim statement.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ed wrote:
It *is* that simple! I better go back and reread that section on
arrays! Thank you, Jonathan.

One more thing I think I _did_ understand - I've used ReDim Preserve
with a single dimension to add another value to the array while
writing to it, but you can't use Preserve with a multidimensional
array, correct? So I would need to declare this with more than the
paces I will need, then ReDim (if I want to) to match the actual
number of values assigned?

Ed

"Jonathan West" <jwest@xxxxxxxx> wrote in message
news:eDtf8nAWGHA.5808@xxxxxxxxxxxxxxxxxxxxxxx
Hi Ed,

try this

For y = 1 to 4
For x = 1 to 10
Table.Cell(x, y).Range.Text= MyArray(x, y)
Next x
Next y


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition
www.classicvb.org


"Ed" <ed_millis@xxxxxxxxxxxxxxxxx> wrote in message
news:OiO9PfAWGHA.4960@xxxxxxxxxxxxxxxxxxxxxxx
I haven't worked much with arrays, so please forgive me if this is
a basic question. I want to collect a series of text elements to
write into a table all in one go, rather than write to the table
one by one as collected. If I only had a one column table, I would
just say For x = 1 to 10
Table.Cell(x, 1).Text = Array(x)
Next x

But when I've got four columns, how do I say
Table.Cell(x, y).Text = Array(x,y) ??
(I figure that's not the correct way to do it - but it was the
closest I could come to explaining it.)
Any help is appreciated.

Ed


.



Relevant Pages

  • Re: User Define Array Data Type - Subscript out of range
    ... ReDim Preserve xArray.IntInputOrder ... ' Load Array ... strDataTypeAs String ... Dim rs As ADODB.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • Re: What does Redim Preserve do in term of memory
    ... I believe Redim Preserve creates a new array with the specified bounds and ... then does an element-by-element copy from the old array to the new array, ... Dim AllocatedToBound As Long ... Dim Ndx As Long ...
    (microsoft.public.excel.programming)
  • Re: Variables in Declaring an Array
    ... two-dim array. ... How can I get "redim preserve myarray" to work? ... Jim Thomlinson wrote: ... dim myArray() as sting ...
    (microsoft.public.excel.programming)
  • Re: Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D ar
    ... I can't follow the values you are using to redim Preserve in your code but ... What I do is start by Redim'ing an array with known absolute minimum number ... If during the process I need an extra last dimension I use ... where Arr has been declared with L-base 1 and numRows & numCols represent ...
    (microsoft.public.excel.programming)
  • Re: simple 2 dimensional array problem
    ... ReDim Preserve CDInfowould have to be ReDim Preserve ... you are creating an array with three elements. ... Dim ItemSet As Object ... For Each Item In ItemSet ...
    (comp.lang.basic.visual.misc)