View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Post Tenebras Lux Post Tenebras Lux is offline
external usenet poster
 
Posts: 41
Default Array data to Range: Only first value written

I have created an array that stores prices. When my code writes the values
of the array (single dimension, about 1500 elements), it writes the value of
the first element to every cell of the worksheet range. Relevant code is as
follows:

Dim Px As Single, EMA_0 As Single, EMA_1 As Single
Dim arEMA() As Single

nData = UBound(arPxData())
ReDim arEMA(nData)

arEMA(1) = arPxData(1)
For i = 2 To nData
arEMA(i) = (2 / (1 + nPeriods) * (arPxData(i) - arPxData(i - 1))) +
arPxData(i - 1)
Next

With Range("OutEMA0Head")
Range(.Offset(1, 0), .Offset(nData, 0)).Clear
Range(.Offset(1, 0), .Offset(nData, 0)) = arEMA
End With

The Watch window shows that each element of the arEMA is filled with
different values. The .Clear line works perfectly. So does = arEMA line,
except all 1500 cells are filled with the same value - the first element of
arEMA.

I don't want to have to loop through every cell, but it makes no sense to me
why this is happening.

Any suggestions would be appreciated.