Setting Range = Array of User-Defined Types

S

steve4446

I have a large array ['P()'] of Public Types ['PORecord'] from which I would
like to write some of the sub-types [eg. 'PO_OutputDate'] to a spreadsheet at
the end of a set of calculations. Currently I am using a "For...Next" loop,
but this is slooww.

Currently my Code goes something like this:

'Start Code
For q = UBound(P, 1) To LBound(P, 1)
Sheet1. Range(Info.PO_Output_Col & q).Value = P(q).PO_OutputDate
Next q
'End Code

What I would like to do is write all the OutputDates in the array at once to
a range rather than stepping through it bit by bit. This is what I had in
mind...

'start code
Sheet1.Range("Z:Z") = P().PO_OutputDate
'end code

.... however I get an "invalid qualifier" error. What am I doing wrong? How
can I fix this?

Thanks in advance,
Steve
 
C

Charlie

Not tested but something like:

Dim i As Long
Dim nDate As Long
Dim DateArray() As Variant

nDate = UBound(P)
ReDim DateArray(nDate, 1)

For i = 1 To nDate
DateArray(i, 1) = P(i).PO_OutputDate
Next i

Range("Z1:Z" & nDate) = DateArray
 
C

Charlie

Oh, BTW, I use Option Base 1 always so adjust your array dimensions
accordingly if you use zero-based 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

Top