Consulting

Results 1 to 4 of 4

Thread: Help with Sub

  1. #1

    Help with Sub

    I am missing something from my code for my homework.

    Mycovar
    Y X
    17 20
    2 24
    36 29
    48 35
    12 43
    22 52
    88 63
    55 76
    33 91
    45 10
    11 33
    12 16
    13 92
    14 23
    15 78
    16 34
    17 40
    18 48
    19 57
    20 69
    #VALUE!
    The function is a summation with the formula listed below (x(i)-xbar)*(y(i)-ybar).

    Here is what I have so far:

    Function MyCovar(x, y)
    xbar = Application.WorksheetFunction.Average(x)
        ybar = Application.WorksheetFunction.Average(y)
        Nper = x.Rows.Count
        Sum = 0
        For i = 1 To Nper
            Sum = (x(i) - xbar) * (y(i) - ybar)
        Next i
        MyCovar = Sum
        End Function
    Thanks to any answers.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I am missing something from my code for my homework.
    I'm missing what it is that you're missing

    Guessing ...

    For i = 1 ..... starts in row 1 which has "Y" and "X" in it. Maybe For i = 2 To ... ???
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sum = (x(i) - xbar) * (y(i) - ybar)
    And
    Sum = (x(x.Rows.Count) - xbar) * (y(x.Rows.Count) - ybar)

    Are identical in effect. That is: You can replace one line with the other with no affect on the outcome of your code.

    Socrates asks, "Why is that true?"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Quote Originally Posted by SamT View Post
    Socrates asks, "Why is that true?"
    Funny, you don't look like a Socrates
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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