PDA

View Full Version : Help with Sub



jrhess003
04-27-2016, 01:53 PM
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.

Paul_Hossler
04-27-2016, 02:28 PM
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 ... ???

SamT
04-27-2016, 07:00 PM
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?"

Paul_Hossler
04-28-2016, 08:11 AM
Socrates asks, "Why is that true?"

Funny, you don't look like a Socrates :devil2: