ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Put values into excel range from single dimension array (https://www.excelbanter.com/excel-programming/354348-put-values-into-excel-range-single-dimension-array.html)

[email protected]

Put values into excel range from single dimension array
 
I'm having a tough time getting all the values out of an array and into
an excel range. When I try to do it I only get the first value in the
array in all the cells in the range. Instead I want each element.
Here's the code:



Dim aSMASMA As Variant
Dim aTradedecision(1996) As Variant
Dim j As Integer
Dim element As Variant
Dim intTotaltradingdays As Integer


aSMASMA = Range("K5:L2000").Value
j = 0


For Each element In aSMASMA
If aSMASMA(j + 1, 2) < Empty Then
aTradedecision(j) = aSMASMA(j + 1, 1) - aSMASMA(j + 1,
2)
j = j + 1
Else
Exit For
End If
Next

intTotaltradingdays = j

Range("M5").Resize(j).Value = aTradedecision()


Tom Ogilvy

Put values into excel range from single dimension array
 
Range("M5").Resize(j).Value = _
Application.Transpose(aTradedecision())

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
I'm having a tough time getting all the values out of an array and into
an excel range. When I try to do it I only get the first value in the
array in all the cells in the range. Instead I want each element.
Here's the code:



Dim aSMASMA As Variant
Dim aTradedecision(1996) As Variant
Dim j As Integer
Dim element As Variant
Dim intTotaltradingdays As Integer


aSMASMA = Range("K5:L2000").Value
j = 0


For Each element In aSMASMA
If aSMASMA(j + 1, 2) < Empty Then
aTradedecision(j) = aSMASMA(j + 1, 1) - aSMASMA(j + 1,
2)
j = j + 1
Else
Exit For
End If
Next

intTotaltradingdays = j

Range("M5").Resize(j).Value = aTradedecision()




[email protected]

Put values into excel range from single dimension array
 
Thx again Tom...that worked



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

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