+ Reply to Thread
Results 1 to 4 of 4

Put values into excel range from single dimension array

  1. #1
    scottzuehl@gmail.com
    Guest

    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()


  2. #2
    Tom Ogilvy
    Guest

    Re: Put values into excel range from single dimension array

    Range("M5").Resize(j).Value = _
    Application.Transpose(aTradedecision())

    --
    Regards,
    Tom Ogilvy


    <scottzuehl@gmail.com> wrote in message
    news:1140817299.796699.185030@e56g2000cwe.googlegroups.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()
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: Put values into excel range from single dimension array

    Range("M5").Resize(j).Value = _
    Application.Transpose(aTradedecision())

    --
    Regards,
    Tom Ogilvy


    <scottzuehl@gmail.com> wrote in message
    news:1140817299.796699.185030@e56g2000cwe.googlegroups.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()
    >




  4. #4
    scottzuehl@gmail.com
    Guest

    Re: Put values into excel range from single dimension array

    Thx again Tom...that worked


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1