We help IT Professionals succeed at work.

VBA  Transfer Array Values into a Range

bishop3000
bishop3000 asked
on
1,194 Views
Last Modified: 2008-01-09
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!
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2008
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Eureka!
Thank you Kevin.

-Michael
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.