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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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
[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][td="bgcolor:#C0C0C0"]
F​
[/td][td="bgcolor:#C0C0C0"]
G​
[/td][td="bgcolor:#C0C0C0"]
H​
[/td][td="bgcolor:#C0C0C0"]
I​
[/td][td="bgcolor:#C0C0C0"]
J​
[/td][td="bgcolor:#C0C0C0"]
K​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
Data 1
[/td][td="bgcolor:#F3F3F3"]
Data 2
[/td][td="bgcolor:#F3F3F3"]
Data 3
[/td][td="bgcolor:#F3F3F3"]
Data 4
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
Data 1
[/td][td="bgcolor:#F3F3F3"]
Data 2
[/td][td="bgcolor:#F3F3F3"]
Data 3
[/td][td="bgcolor:#F3F3F3"]
Data 4
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
70​
[/td][td]
77​
[/td][td]
79​
[/td][td]
88​
[/td][td][/td][td="bgcolor:#F3F3F3"]
Data 1
[/td][td="bgcolor:#CCFFCC"]
1​
[/td][td="bgcolor:#CCFFCC"]
-0.19294​
[/td][td="bgcolor:#CCFFCC"]
0.445674​
[/td][td="bgcolor:#CCFFCC"]
0.238539​
[/td][td]G2: =CORREL(A$2:A$21, INDEX($A$2:$D$21, 0, ROWS($G$1:G1)))[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
54​
[/td][td]
48​
[/td][td]
18​
[/td][td]
40​
[/td][td][/td][td="bgcolor:#F3F3F3"]
Data 2
[/td][td="bgcolor:#CCFFCC"]
-0.19294​
[/td][td="bgcolor:#CCFFCC"]
1​
[/td][td="bgcolor:#CCFFCC"]
0.115421​
[/td][td="bgcolor:#CCFFCC"]
0.273441​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
90​
[/td][td]
95​
[/td][td]
99​
[/td][td]
74​
[/td][td][/td][td="bgcolor:#F3F3F3"]
Data 3
[/td][td="bgcolor:#CCFFCC"]
0.445674​
[/td][td="bgcolor:#CCFFCC"]
0.115421​
[/td][td="bgcolor:#CCFFCC"]
1​
[/td][td="bgcolor:#CCFFCC"]
0.312972​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
6​
[/td][td]
79​
[/td][td]
54​
[/td][td]
37​
[/td][td][/td][td="bgcolor:#F3F3F3"]
Data 4
[/td][td="bgcolor:#CCFFCC"]
0.238539​
[/td][td="bgcolor:#CCFFCC"]
0.273441​
[/td][td="bgcolor:#CCFFCC"]
0.312972​
[/td][td="bgcolor:#CCFFCC"]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
100​
[/td][td]
15​
[/td][td]
80​
[/td][td]
47​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]
86​
[/td][td]
42​
[/td][td]
91​
[/td][td]
60​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td]
57​
[/td][td]
84​
[/td][td]
97​
[/td][td]
90​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]
5​
[/td][td]
39​
[/td][td]
21​
[/td][td]
92​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]
1​
[/td][td]
45​
[/td][td]
51​
[/td][td]
5​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td]
90​
[/td][td]
24​
[/td][td]
68​
[/td][td]
86​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td]
25​
[/td][td]
96​
[/td][td]
82​
[/td][td]
65​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td]
14​
[/td][td]
74​
[/td][td]
20​
[/td][td]
33​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td]
1​
[/td][td]
77​
[/td][td]
40​
[/td][td]
19​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
15​
[/td][td]
91​
[/td][td]
59​
[/td][td]
10​
[/td][td]
18​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
16​
[/td][td]
69​
[/td][td]
31​
[/td][td]
91​
[/td][td]
16​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
17​
[/td][td]
1​
[/td][td]
34​
[/td][td]
7​
[/td][td]
53​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
18​
[/td][td]
13​
[/td][td]
57​
[/td][td]
85​
[/td][td]
55​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
19​
[/td][td]
59​
[/td][td]
30​
[/td][td]
52​
[/td][td]
67​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
20​
[/td][td]
61​
[/td][td]
98​
[/td][td]
81​
[/td][td]
96​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
21​
[/td][td]
60​
[/td][td]
1​
[/td][td]
88​
[/td][td]
30​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
 
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,224,765
Messages
6,180,845
Members
453,001
Latest member
coulombevin

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