How to Create a Customized Function in Excel VBA for Multiple Matrices Multiplication?

louqiyue

New Member
Joined
Mar 18, 2019
Messages
1
I want to create a function in Excel VBA that can do matrices multiplication for multiple matrices (undefined numbers of augments). The following is my code (I use ParamArray in this function), but it returns an error. Could anyone help me debug it?

Function MultMMult(ParamArray X() As Variant)
Dim aMatrix As Variant
For aMatrix = LBound(X) To UBound(X)
MultMMult = Application.WorksheetFunction.MMult(MultMMult, X(aMatrix))
Next aMatrix
End Function
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Code:
Function MultMMult(ParamArray avInp() As Variant) As Variant
  Dim i             As Long

  MultMMult = avInp(0)

  With WorksheetFunction
    For i = 1 To UBound(avInp)
      MultMMult = .MMult(MultMMult, avInp(i))
    Next i
  End With
End Function

A​
B​
C​
D​
1​
2​
4​
10​
2​
7​
2​
1​
3​
6​
4​
6​
4​
5​
1​
4​
2​
6​
9​
8​
5​
7​
6​
7​
6​
8​
9​
5​
7​
2​
10​
1​
6​
7​
11​
10​
9​
10​
12​
13​
1440​
2102​
1806​
A13:C15: {=MultMMult(A1:C3, A5:C7, A9:C11)}
14​
506​
793​
719​
15​
1168​
1746​
1522​
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

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