[英]unable to get the MMult property of the WorksheetFunction
everyone, I got a strange problem, please help. 大家好,我遇到了一个奇怪的问题,请帮忙。
the error message is: 错误消息是:
Run-time error '1004'
运行时错误'1004'
Unable to get the
MMult
property of theWorksheetFunction
class无法获取
WorksheetFunction
类的MMult
属性
1, I use a program name is " schedule
" to automaticly run my VBA program everyday, but the VBA program will fail everyday, but when I control my "schedule program" to automatically run it again to try to reproduce this error, I can't get it, it run smooth. 1,我使用程序名称“
schedule
”来每天自动运行我的VBA程序,但是VBA程序每天都会失败,但是当我控制我的“计划程序”再次自动运行它以尝试重现此错误时,我可以得到它,它运行顺利。
2, When this error occured, Excel will show [end] [debug] window, I click [debug] and press [F5] , it run smooth; 2,发生此错误时,Excel将显示[end] [debug]窗口,单击[debug]并按[F5] ,运行平稳; it supposes show error again if parameters for MMult are incorrect.
如果MMult的参数不正确,它会再次显示错误。
3, I have written a sub to dump my data which use in mmult
, it are same in error occur and no error. 3,我写了一个子转储我的数据,在
mmult
中使用,它是相同的错误发生,没有错误。
so, I can assume the two parameters for mmult
are correct, but why I got the error message everyday? 所以,我可以假设
mmult
的两个参数是正确的,但为什么我每天都收到错误信息?
this most hard thing is it is hard to reproduce this error. 最困难的是很难重现这个错误。
code: 码:
Public Function Regression(ByVal X As Variant, ByVal y As Variant)
writelog ("Regression")
writelog ("dump x")
Call dumpRange(X, 2)
writelog ("dump y")
Call dumpRange(y, 1)
Dim xtrans, temp, temp2, b
xtrans = Application.WorksheetFunction.Transpose(X)
temp = Application.WorksheetFunction.MMult(xtrans, X) ' occour error on this line
temp = Application.WorksheetFunction.MInverse(temp)
temp2 = Application.WorksheetFunction.MMult(xtrans, y)
b = Application.WorksheetFunction.MMult(temp, temp2)
Regression = b
End Function
X is a Range like this X是这样的范围
1 0.34343323
1 1.32323323
1 1.21111221
1 0.33444232
. ......
Window 7 home preminum 64bit Window 7 home preminum 64bit
office 2010 professional 64bit / 32bit sp1 office 2010专业64bit / 32bit sp1
I had the same problem. 我有同样的问题。 But it turned out mine was caused by a dimension problem.
但事实证明我的是由尺寸问题引起的。
I did: 我做了:
Redim Y(obs)
Redim X(obs,3)
Xtransposed = Application.worksheetfunction.transpose(X)
MMult = Application.worksheetfunction.mmult(Xtransposed, Y)
While I should have done Redim Y(obs,1) to make the code work. 虽然我应该做Redim Y(obs,1)来使代码工作。
So: 所以:
Redim Y(obs,1)
Redim X(obs,3)
Xtransposed = Application.worksheetfunction.transpose(X)
MMult = Application.worksheetfunction.mmult(Xtransposed, Y)
Try This. 尝试这个。 I think this is where you are getting your error
我认为这是你得到错误的地方
temp = Application.WorksheetFunction.MMult(xtrans,
Application.Transpose(X))
我重新安装了我的操作系统和办公室,现在工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.