[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1168
  • Last Modified:

VBA Transfer Array Values into a Range

Hi,
I'm trying to store number averages in an array, via a For-Next loop--then transfer the averages into a range. The following code fails to insert the values into the range:

    Sub Averages()
    Dim myarray(4) As Variant, i As Integer, avg As Integer

    For i = 2 To 4 Step 2
        avg = WorksheetFunction.Average(Array(Cells(1, i), Cells(3, i + 1)))
            myarray(i) = avg
    Next i

    Range("a5:b5").Value = myarray()

    End Sub

Your help is greatly appreciated!
0
bishop3000
Asked:
bishop3000
1 Solution
 
zorvek (Kevin Jones)ConsultantCommented:
Try:


    Sub Averages()
    Dim myarray(1 to 2) As Variant, i As Integer, avg As Integer

    For i = 2 To 4 Step 2
        avg = WorksheetFunction.Average(Array(Cells(1, i), Cells(3, i + 1)))
            myarray(i \ 2) = avg
    Next i

    Range("a5:b5").Value = myarray()

    End Sub

Kevin
0
 
bishop3000Author Commented:
Eureka!
Thank you Kevin.

-Michael
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now