ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Matrix Multiplication Function creation (https://www.excelbanter.com/excel-programming/285560-matrix-multiplication-function-creation.html)

Gabriel[_3_]

Matrix Multiplication Function creation
 
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

Tom Ogilvy

Matrix Multiplication Function creation
 
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

--
Regards,
Tom Ogilvy

"Gabriel" wrote in message
om...
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





All times are GMT +1. The time now is 06:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com