Matrix Multiplication Function creation

  • Thread starter Thread starter Gabriel
  • Start date Start date
G

Gabriel

Hello,

I want to create a function in vba that performs the following
calculation:

{=MMULT(A,B)}

A B A*B

1 3 4 6 19 27
2 4 5 7 28 40


I want to select the appropriate range,the function box to pop up so
that I could select A then B and then get the same result that I've
obtained in worksheet.

Function AxB (A,B) as variant
AxB = Application.WorksheetFunction.MMult(A, B)
End Function

What should I change or add to the above function to do what should be
done?

Thank you in advance
Gabriel
 
Sub Main()
Dim A as Range, B as Range
On error Resume Next
set A = Application.InputBox("Select first range using mouse",type:=8)
if not A is nothing then
set B = Application.InputBox("Select second range using mouse",type:=8)
if B is nothing then exit sub
else
exit sub
End if
On Error goto 0
' add some error checking on the size of the ranges
varr = AxB(A,B)
for i = lbound(varr,1) to ubound(varr,1)
for j = lbound(varr,2) to bound(varr,2)
debug.print i,j, varr(i,j)
Next
Next
End Sub


Function AXB(a as range, b as range)
AxB = Application.WorksheetFunction.MMult(A, B)
End Function
 
Back
Top