我想在vba中编写这个公式。
=MMULT(TRANSPOSE(F124:F370-L124),G124:G370-L125)/246
我写的vba中的代码如下所示:
Sheets("1.A").Cells(124, 14) = Application.WorksheetFunction.MMult(Application.WorksheetFunction.Transpose(Worksheets("1.A").Range("F" & matchStartRow & ":F" & matchEndRow) - Cells(124, 12)), Worksheets("1.A").Range("G" & matchStartRow & ":G" & matchEndRow) - Cells(125, 12)) / (matchEndRow - matchStartRow)
但它给了我一个类型不匹配的错误。不知道它来自哪里
答案 0 :(得分:5)
将EVALUATE
直接用作
Sheets("1.A").Cells(124, 14) = Evaluate("=MMULT(TRANSPOSE(F124:F370-L124),G124:G370-L125)/246")
或使用您的变量
Dim strEval As String
matchStartRow = 124
matchEndRow = 370
strEval = "=MMULT(TRANSPOSE(F" & matchStartRow & ":F" & matchEndRow & "-L124),G" & matchStartRow & ":G" & matchEndRow & "-L125)/(" & matchEndRow & " - " & matchStartRow & ")"
Sheets("1.A").Cells(124, 14) = Evaluate(strEval)