Unable to get the Pearson Property of the worksheetfunction class

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am receiving the error "Unable to get the Pearson Property of the WorksheetFunction Class" Runtime Error on the line below.

Arg1 and Arg2 are both Range variables. J, and i are integer variables.

I would like the value of Cells(j,i) to be the value of the Pearson WorksheetFunction.

Code:
Workbooks("Matrix.xls").Worksheets("Paper2").Cells(J, i) = Application.WorksheetFunction.Pearson(arg1, arg2)

Thanks!
 
This is not what's causing your problem (ATM, anyway), but you are calculating e and f separately, and they must be the same; Correl (and Pearson) require equal-size arrays.
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
And the assignment of e and f needs to be in that With block, for the same reason as before.
 
Upvote 0
And, unless your heart is set on VBA, this would be easy to do with formulas.
 
Upvote 0
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
1​
Data 1
Data 2
Data 3
Data 4
Data 1
Data 2
Data 3
Data 4
2​
70​
77​
79​
88​
Data 1
1​
-0.19294​
0.445674​
0.238539​
G2: =CORREL(A$2:A$21, INDEX($A$2:$D$21, 0, ROWS($G$1:G1)))
3​
54​
48​
18​
40​
Data 2
-0.19294​
1​
0.115421​
0.273441​
4​
90​
95​
99​
74​
Data 3
0.445674​
0.115421​
1​
0.312972​
5​
6​
79​
54​
37​
Data 4
0.238539​
0.273441​
0.312972​
1​
6​
100​
15​
80​
47​
7​
86​
42​
91​
60​
8​
57​
84​
97​
90​
9​
5​
39​
21​
92​
10​
1​
45​
51​
5​
11​
90​
24​
68​
86​
12​
25​
96​
82​
65​
13​
14​
74​
20​
33​
14​
1​
77​
40​
19​
15​
91​
59​
10​
18​
16​
69​
31​
91​
16​
17​
1​
34​
7​
53​
18​
13​
57​
85​
55​
19​
59​
30​
52​
67​
20​
61​
98​
81​
96​
21​
60​
1​
88​
30​
 
Upvote 0
When I watch the code and step through it with F8 the variable "a" reads "expression not defined in context" in the value area...further over in the context area it reads VBAProject.

This is different from the other variable "b" which is very similar and if functioning accordingly. The primary difference between the two is the "context". "b" reads "VBAProject.Module84.CMatrixUpdate"

How can I change the context?
 
Upvote 0
Does post #14 essentially show what you're trying to do?
 
Upvote 0
Code:
Sub CMatrixUpdate()
  Dim rInp          As Range
  Dim rOut          As Range
  Dim sArg1         As String
  Dim sArg2         As String
  Dim sArg3         As String

  Set rInp = Workbooks("LOGREG_INPUT.xls").Worksheets("Paper1").Range("A2")
  Set rInp = Range(rInp, rInp.End(xlDown).End(xlToRight))

  Application.Goto rInp
  Stop  ' does that look correct?

  With rInp.Columns
    Set rOut = Workbooks("Matrix.xls").Worksheets("Paper2").Range("A2").Resize(.Count, .Count)
  End With

  Application.Goto rOut
  Stop  ' does that look correct?

  With rInp
    sArg1 = .Columns(1).Address(RowAbsolute:=True, ColumnAbsolute:=False, External:=True)
    sArg2 = .Address(RowAbsolute:=True, ColumnAbsolute:=True, External:=True)
    sArg3 = rOut.Cells(1).Address(RowAbsolute:=True, ColumnAbsolute:=True, External:=False) & ":" & _
            rOut.Cells(1).Address(False, False)
    rOut.Formula = "=CORREL(" & sArg1 & ", INDEX(" & sArg2 & ", 0, ROWS(" & sArg3 & ")))"
    ' rOut.Value = rOut.Value ' uncomment this line if you just want values
  End With
End Sub
 
Upvote 0
Thanks for the input...ill have to spend more time with the chunk above to see if I can get it running.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top