+ Reply to Thread
Results 1 to 2 of 2

Thread: average function not defined in value statement

  1. #1
    Registered User
    Join Date
    12-27-2011
    Location
    Bothell
    MS-Off Ver
    Excel 2010
    Posts
    5

    average function not defined in value statement

    The code is meant to take a set of 10,000 observations of variable x and y and plug each observation set into the equation defined as fin and take the average of the results. For some reason when I try to use the average function when defining the cell(2,7) it is saying that the average function is not defined. Also for a while i was having trouble with the exp predefined function when trying to define fin(i) until i finally copyed and pasted the function from the worksheet. And again with defining the t(i) variable I tryed to use the SQRT() predefined function until I restated it the way it is now. can anyone tell me why vba is having trouble recognizing its functions when I type them in in a value statement?
    Sub udsim3()
    Dim x(1 To 10000), y(1 To 10000), t(1 To 10000), fin(1 To 10000), i
    For i = 1 To 10000
    x(i) = Cells(2 * i + 9999, "D")
    y(i) = Cells(2 * i + 10000, "D")
    t(i) = (y(i) ^ (0.5)) * x(i)
    fin(i) = Exp((-3 * t(i)) - y(i)) * (y(i) ^ 1.5) * (1 + 3 * t(i))
    Cells(i + 1, "P") = fin(i)
    Next i
    Cells(2, 7) = Average(fin)
    End Sub
    Last edited by Truss123; 01-23-2012 at 12:52 PM.

  2. #2
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: average function not defined in value statement

    Average is an Excel function, not VBA

    Cells(2, 7).Value = WorksheetFunction.Average(fin)
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

+ 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.2.0