Reputation: 85
I’m struggling with “Run-time error ‘1004’: Unable to get the MMult property of the WorksheetFunction class”. I made the code as simple as possible but it still does not work.
I’d be grateful for a hint
Sub Matrix_Computation3()
Dim ws3 As Worksheet
Dim ArrP As Variant
Dim ArrCW As Variant
Dim Temp As Variant
Dim Size
Set ws3 = Sheets("STEP 3")
Size = 6
ReDim ArrP(1 To 1, 1 To Size)
ReDim ArrCW(1 To Size, 1)
ArrP(1, 1) = 0.2
ArrP(1, 2) = 0.2
ArrP(1, 3) = 0.2
ArrP(1, 4) = 0.2
ArrP(1, 5) = 0.2
ArrP(1, 6) = 0.2
ArrCW(1, 1) = 0.3
ArrCW(2, 1) = 0.3
ArrCW(3, 1) = 0.3
ArrCW(4, 1) = 0.3
ArrCW(5, 1) = 0.3
ArrCW(6, 1) = 0.3
Temp = ws3.Application.WorksheetFunction.MMult(ArrP, ArrCW) ' here is an error
MsgBox Temp(1)
End Sub
Upvotes: 2
Views: 9718
Reputation: 21619
You're passing MMULT
the wrong kind of array. This is a worksheet function, not a VBA function. The worksheet version of an array is a range of cells, so put the values into two worksheet ranges and refer to them there.
For example, part of your code might be:
Dim range1 as Range, range2 as Range
Set range1 = ws3.Range("A1:D1")
Set range2 = ws3.Range("E1:E4")
Temp = ws3.Application.WorksheetFunction.MMult(range1, range2)
Also note that the number of columns in array1 must be the same as the number of rows in array2, and both arrays must contain only numbers.
Perhaps get the function working on the worksheet before trying to call it from VBA.
Office.com : MMULT
function (Excel)
Office.com : WorksheetFunction.MMult
method (VBA)
Upvotes: 1