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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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

[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][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td]
2​
[/td][td]
4​
[/td][td]
10​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
7​
[/td][td]
2​
[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
6​
[/td][td]
4​
[/td][td]
6​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
1​
[/td][td]
4​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
9​
[/td][td]
8​
[/td][td]
5​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]
6​
[/td][td]
7​
[/td][td]
6​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]
5​
[/td][td]
7​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]
1​
[/td][td]
6​
[/td][td]
7​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td]
10​
[/td][td]
9​
[/td][td]
10​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td="bgcolor:#E5E5E5"]
1440​
[/td][td="bgcolor:#E5E5E5"]
2102​
[/td][td="bgcolor:#E5E5E5"]
1806​
[/td][td]A13:C15: {=MultMMult(A1:C3, A5:C7, A9:C11)}[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td="bgcolor:#E5E5E5"]
506​
[/td][td="bgcolor:#E5E5E5"]
793​
[/td][td="bgcolor:#E5E5E5"]
719​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
15​
[/td][td="bgcolor:#E5E5E5"]
1168​
[/td][td="bgcolor:#E5E5E5"]
1746​
[/td][td="bgcolor:#E5E5E5"]
1522​
[/td][td][/td][/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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